Search in sources :

Example 1 with JSObject

use of com.getcapacitor.JSObject 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);
    }
}
Also used : MyRunnable(com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 2 with JSObject

use of com.getcapacitor.JSObject 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;
    }
}
Also used : HashMap(java.util.HashMap) JSObject(com.getcapacitor.JSObject) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 3 with JSObject

use of com.getcapacitor.JSObject 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);
    }
}
Also used : MyRunnable(com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 4 with JSObject

use of com.getcapacitor.JSObject 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);
    }
}
Also used : MyRunnable(com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Example 5 with JSObject

use of com.getcapacitor.JSObject 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);
    }
}
Also used : MyRunnable(com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable) JSObject(com.getcapacitor.JSObject) PluginMethod(com.getcapacitor.PluginMethod)

Aggregations

JSObject (com.getcapacitor.JSObject)169 PluginMethod (com.getcapacitor.PluginMethod)93 JSONException (org.json.JSONException)28 JSONObject (org.json.JSONObject)20 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)16 JSArray (com.getcapacitor.JSArray)14 Radar (io.radar.sdk.Radar)12 Uri (android.net.Uri)11 Location (android.location.Location)9 JSONArray (org.json.JSONArray)7 ArrayList (java.util.ArrayList)6 NotNull (org.jetbrains.annotations.NotNull)6 Nullable (org.jetbrains.annotations.Nullable)6 ParseException (java.text.ParseException)5 Intent (android.content.Intent)4 FirebaseUser (com.google.firebase.auth.FirebaseUser)4 Gson (com.google.gson.Gson)4 Date (java.util.Date)4 HashMap (java.util.HashMap)4 Test (org.junit.Test)4