use of com.getcapacitor.PluginMethod in project capacitor-video-player by jepiqueau.
the class CapacitorVideoPlayerPlugin method getCurrentTime.
@PluginMethod
public void getCurrentTime(final PluginCall call) {
this.call = call;
JSObject ret = new JSObject();
ret.put("method", "getCurrentTime");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.resolve(ret);
return;
}
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
JSObject ret = new JSObject();
ret.put("method", "getCurrentTime");
if (fsFragment != null) {
int curTime = fsFragment.getCurrentTime();
ret.put("result", true);
ret.put("value", curTime);
call.resolve(ret);
} else {
ret.put("result", false);
ret.put("message", "Fullscreen fragment is not defined");
call.resolve(ret);
}
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.resolve(ret);
}
}
use of com.getcapacitor.PluginMethod in project capacitor-video-player by jepiqueau.
the class CapacitorVideoPlayerPlugin method initPlayer.
@PluginMethod
public void initPlayer(PluginCall call) {
this.call = call;
final JSObject ret = new JSObject();
ret.put("method", "initPlayer");
ret.put("result", false);
// Check if running on a TV Device
isTV = isDeviceTV(context);
Log.d(TAG, "**** isTV " + isTV + " ****");
String _mode = call.getString("mode");
if (_mode == null) {
ret.put("message", "Must provide a Mode (fullscreen/embedded)");
call.resolve(ret);
return;
}
mode = _mode;
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("message", "Must provide a PlayerId");
call.resolve(ret);
return;
}
videoRate = 1f;
if (call.getData().has("rate")) {
Float mRate = call.getFloat("rate");
if (isInRate(rateList, mRate)) {
videoRate = mRate;
}
}
Boolean _exitOnEnd = true;
if (call.getData().has("exitOnEnd")) {
_exitOnEnd = call.getBoolean("exitOnEnd");
}
exitOnEnd = _exitOnEnd;
Boolean _loopOnEnd = false;
if (call.getData().has("loopOnEnd")) {
_loopOnEnd = call.getBoolean("loopOnEnd");
}
if (!exitOnEnd)
loopOnEnd = _loopOnEnd;
Boolean _pipEnabled = true;
if (call.getData().has("pipEnabled")) {
_pipEnabled = call.getBoolean("pipEnabled");
}
pipEnabled = _pipEnabled;
if ("fullscreen".equals(mode)) {
fsPlayerId = playerId;
String url = call.getString("url");
if (url == null) {
ret.put("message", "Must provide an url");
call.resolve(ret);
return;
}
String subtitle = "";
if (call.getData().has("subtitle")) {
subtitle = call.getString("subtitle");
}
String language = "";
if (call.getData().has("language")) {
language = call.getString("language");
}
JSObject subTitleOptions = new JSObject();
if (call.getData().has("subtitleOptions")) {
subTitleOptions = call.getObject("subtitleOptions");
}
AddObserversToNotificationCenter();
Log.v(TAG, "display url: " + url);
Log.v(TAG, "display subtitle: " + subtitle);
Log.v(TAG, "display language: " + language);
if (url.equals("internal")) {
createPickerVideoFragment(call);
} else {
// get the videoPath
videoPath = filesUtils.getFilePath(url);
// get the subTitlePath if any
if (subtitle != null && subtitle.length() > 0) {
subTitlePath = filesUtils.getFilePath(subtitle);
} else {
subTitlePath = null;
}
Log.v(TAG, "*** calculated videoPath: " + videoPath);
Log.v(TAG, "*** calculated subTitlePath: " + subTitlePath);
if (videoPath != null) {
createFullScreenFragment(call, videoPath, videoRate, exitOnEnd, loopOnEnd, pipEnabled, subTitlePath, language, subTitleOptions, isTV, playerId, false, null);
} else {
Map<String, Object> info = new HashMap<String, Object>() {
{
put("dismiss", "1");
}
};
NotificationCenter.defaultCenter().postNotification("playerFullscreenDismiss", info);
ret.put("message", "initPlayer command failed: Video file not found");
call.resolve(ret);
return;
}
}
} else if ("embedded".equals(mode)) {
ret.put("message", "Embedded Mode not implemented");
call.resolve(ret);
return;
}
}
use of com.getcapacitor.PluginMethod in project capacitor-video-player by jepiqueau.
the class CapacitorVideoPlayerPlugin method getMuted.
@PluginMethod
public void getMuted(final PluginCall call) {
this.call = call;
JSObject ret = new JSObject();
ret.put("method", "getMuted");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.resolve(ret);
return;
}
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
JSObject ret = new JSObject();
ret.put("method", "getMuted");
if (fsFragment != null) {
boolean value = fsFragment.getMuted();
ret.put("result", true);
ret.put("value", value);
call.resolve(ret);
} else {
ret.put("result", false);
ret.put("message", "Fullscreen fragment is not defined");
call.resolve(ret);
}
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.resolve(ret);
}
}
use of com.getcapacitor.PluginMethod in project capacitor-video-player by jepiqueau.
the class CapacitorVideoPlayerPlugin method getRate.
@PluginMethod
public void getRate(final PluginCall call) {
this.call = call;
JSObject ret = new JSObject();
ret.put("method", "getRate");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.resolve(ret);
return;
}
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
JSObject ret = new JSObject();
ret.put("method", "getRate");
if (fsFragment != null) {
Float rate = fsFragment.getRate();
ret.put("result", true);
ret.put("value", rate);
call.resolve(ret);
} else {
ret.put("result", false);
ret.put("message", "Fullscreen fragment is not defined");
call.resolve(ret);
}
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.resolve(ret);
}
}
use of com.getcapacitor.PluginMethod in project capacitor-video-player by jepiqueau.
the class CapacitorVideoPlayerPlugin method setVolume.
@PluginMethod
public void setVolume(final PluginCall call) {
this.call = call;
JSObject ret = new JSObject();
ret.put("method", "setVolume");
String playerId = call.getString("playerId");
if (playerId == null) {
ret.put("result", false);
ret.put("message", "Must provide a PlayerId");
call.resolve(ret);
return;
}
Float volume = call.getFloat("volume");
if (volume == null) {
ret.put("result", false);
ret.put("method", "setVolume");
ret.put("message", "Must provide a volume value");
call.resolve(ret);
return;
}
if ("fullscreen".equals(mode) && fsPlayerId.equals(playerId)) {
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
JSObject ret = new JSObject();
ret.put("method", "setVolume");
if (fsFragment != null) {
fsFragment.setVolume(volume);
ret.put("result", true);
ret.put("value", volume);
call.resolve(ret);
} else {
ret.put("result", false);
ret.put("message", "Fullscreen fragment is not defined");
call.resolve(ret);
}
}
});
} else {
ret.put("result", false);
ret.put("message", "player is not defined");
call.resolve(ret);
}
}
Aggregations