Search in sources :

Example 1 with MyRunnable

use of com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable 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);
            }
        }
    });
}
Also used : MyRunnable(com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable) ViewGroup(android.view.ViewGroup) MyRunnable(com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable) FrameLayout(android.widget.FrameLayout) JSObject(com.getcapacitor.JSObject) JSObject(com.getcapacitor.JSObject) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 JSObject (com.getcapacitor.JSObject)1 MyRunnable (com.jeep.plugin.capacitor.capacitorvideoplayer.Notifications.MyRunnable)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1