use of com.getcapacitor.JSObject in project capacitor-video-player by jepiqueau.
the class CapacitorVideoPlayerPlugin method echo.
@PluginMethod
public void echo(PluginCall call) {
String value = call.getString("value");
JSObject ret = new JSObject();
ret.put("value", implementation.echo(value));
call.resolve(ret);
}
use of com.getcapacitor.JSObject in project capacitor-video-player by jepiqueau.
the class CapacitorVideoPlayerPlugin method play.
@PluginMethod
public void play(final PluginCall call) {
this.call = call;
JSObject ret = new JSObject();
ret.put("method", "play");
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", "play");
if (fsFragment != null) {
fsFragment.play();
boolean playing = fsFragment.isPlaying();
ret.put("result", true);
ret.put("value", true);
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.JSObject in project capacitor-video-player by jepiqueau.
the class CapacitorVideoPlayerPlugin method AddObserversToNotificationCenter.
private void AddObserversToNotificationCenter() {
NotificationCenter.defaultCenter().addMethodForNotification("playerItemPlay", new MyRunnable() {
@Override
public void run() {
JSObject data = new JSObject();
data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
data.put("currentTime", this.getInfo().get("currentTime"));
notifyListeners("jeepCapVideoPlayerPlay", data);
return;
}
});
NotificationCenter.defaultCenter().addMethodForNotification("playerItemPause", new MyRunnable() {
@Override
public void run() {
JSObject data = new JSObject();
data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
data.put("currentTime", this.getInfo().get("currentTime"));
notifyListeners("jeepCapVideoPlayerPause", data);
return;
}
});
NotificationCenter.defaultCenter().addMethodForNotification("playerItemReady", new MyRunnable() {
@Override
public void run() {
JSObject data = new JSObject();
data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
data.put("currentTime", this.getInfo().get("currentTime"));
notifyListeners("jeepCapVideoPlayerReady", data);
return;
}
});
NotificationCenter.defaultCenter().addMethodForNotification("playerItemEnd", new MyRunnable() {
@Override
public void run() {
final JSObject data = new JSObject();
data.put("fromPlayerId", this.getInfo().get("fromPlayerId"));
data.put("currentTime", this.getInfo().get("currentTime"));
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
FrameLayout frameLayoutView = getBridge().getActivity().findViewById(frameLayoutViewId);
if (frameLayoutView != null) {
((ViewGroup) getBridge().getWebView().getParent()).removeView(frameLayoutView);
fragmentUtils.removeFragment(fsFragment);
}
fsFragment = null;
NotificationCenter.defaultCenter().removeAllNotifications();
notifyListeners("jeepCapVideoPlayerEnded", data);
}
});
}
});
NotificationCenter.defaultCenter().addMethodForNotification("playerFullscreenDismiss", new MyRunnable() {
@Override
public void run() {
boolean ret = false;
final JSObject data = new JSObject();
if (Integer.valueOf((String) this.getInfo().get("dismiss")) == 1)
ret = true;
data.put("dismiss", ret);
bridge.getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
FrameLayout frameLayoutView = getBridge().getActivity().findViewById(frameLayoutViewId);
if (frameLayoutView != null) {
((ViewGroup) getBridge().getWebView().getParent()).removeView(frameLayoutView);
fragmentUtils.removeFragment(fsFragment);
}
fsFragment = null;
NotificationCenter.defaultCenter().removeAllNotifications();
notifyListeners("jeepCapVideoPlayerExit", data);
}
});
}
});
NotificationCenter.defaultCenter().addMethodForNotification("videoPathInternalReady", new MyRunnable() {
@Override
public void run() {
long videoId = (Long) this.getInfo().get("videoId");
// Get the previously saved call
FrameLayout pickerLayoutView = getBridge().getActivity().findViewById(pickerLayoutViewId);
if (pickerLayoutView != null) {
((ViewGroup) getBridge().getWebView().getParent()).removeView(pickerLayoutView);
fragmentUtils.removeFragment(pkFragment);
}
pkFragment = null;
if (videoId != -1) {
createFullScreenFragment(call, videoPath, videoRate, exitOnEnd, loopOnEnd, pipEnabled, null, null, null, isTV, fsPlayerId, true, videoId);
} else {
Toast.makeText(context, "No Video files found ", Toast.LENGTH_SHORT).show();
Map<String, Object> info = new HashMap<String, Object>() {
{
put("dismiss", "1");
}
};
NotificationCenter.defaultCenter().postNotification("playerFullscreenDismiss", info);
}
}
});
}
use of com.getcapacitor.JSObject in project capacitor-app-update by robingenz.
the class AppUpdatePlugin method readyForUpdate.
private boolean readyForUpdate(PluginCall call, int appUpdateType) {
JSObject ret = new JSObject();
if (this.appUpdateInfo == null) {
ret.put("code", UPDATE_INFO_MISSING);
call.resolve(ret);
return false;
}
if (this.appUpdateInfo.updateAvailability() != UpdateAvailability.UPDATE_AVAILABLE) {
ret.put("code", UPDATE_NOT_AVAILABLE);
call.resolve(ret);
return false;
}
if (!this.appUpdateInfo.isUpdateTypeAllowed(appUpdateType)) {
ret.put("code", UPDATE_NOT_ALLOWED);
call.resolve(ret);
return false;
}
return true;
}
use of com.getcapacitor.JSObject in project capacitor-app-update by robingenz.
the class AppUpdatePlugin method getAppUpdateInfo.
@PluginMethod
public void getAppUpdateInfo(PluginCall call) {
Task<AppUpdateInfo> appUpdateInfoTask = this.appUpdateManager.getAppUpdateInfo();
appUpdateInfoTask.addOnSuccessListener(appUpdateInfo -> {
this.appUpdateInfo = appUpdateInfo;
PackageInfo pInfo;
try {
pInfo = this.getPackageInfo();
} catch (PackageManager.NameNotFoundException e) {
call.reject(ERROR_GET_APP_INFO_FAILED);
return;
}
JSObject ret = new JSObject();
ret.put("currentVersion", String.valueOf(pInfo.versionCode));
ret.put("availableVersion", String.valueOf(appUpdateInfo.availableVersionCode()));
ret.put("updateAvailability", appUpdateInfo.updateAvailability());
ret.put("updatePriority", appUpdateInfo.updatePriority());
ret.put("immediateUpdateAllowed", appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.IMMEDIATE));
ret.put("flexibleUpdateAllowed", appUpdateInfo.isUpdateTypeAllowed(AppUpdateType.FLEXIBLE));
Integer clientVersionStalenessDays = appUpdateInfo.clientVersionStalenessDays();
if (clientVersionStalenessDays != null) {
ret.put("clientVersionStalenessDays", clientVersionStalenessDays);
}
ret.put("installStatus", appUpdateInfo.installStatus());
call.resolve(ret);
});
appUpdateInfoTask.addOnFailureListener(failure -> {
String message = failure.getMessage();
call.reject(message);
});
}
Aggregations