Search in sources :

Example 46 with WritableMap

use of com.facebook.react.bridge.WritableMap in project react-native-navigation by wix.

the class TitleBarSearchButton method onFocusChange.

@Override
public void onFocusChange(View v, boolean hasFocus) {
    WritableMap arguments = Arguments.createMap();
    arguments.putBoolean("hasFocus", hasFocus);
    sendEvent("searchFocusChange", arguments);
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap)

Example 47 with WritableMap

use of com.facebook.react.bridge.WritableMap in project react-native-android-video-editor by RZulfikri.

the class VideoTrim method getVideoInfo.

//    public void setMaxTrimDuration(int maxTrimDuration){
//        this.maxTrimDuration = maxTrimDuration;
//    }
/**
     * Function to get Video Detail, used to get video Duration and Set Video Player Max Duration
     */
private void getVideoInfo(String source) {
    MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
    mediaMetadataRetriever.setDataSource(source);
    duration = Integer.parseInt(mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION));
    if (duration / 60000 >= 10) {
        maxDuration = 600000;
        // videoPlayerControl.setEndPos(maxDuration);
        WritableMap event = Arguments.createMap();
        event.putInt(Events.END_POS, maxDuration);
        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event);
    } else {
        maxDuration = duration;
        rangeSeekEndPos = maxDuration;
        // videoPlayerControl.setEndPos(maxDuration);
        WritableMap event = Arguments.createMap();
        event.putInt(Events.END_POS, maxDuration);
        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event);
    }
    //         Log.e("DEBUG", " "+duration+" "+maxDuration+" "+((minTrimDuration * 100f) / (float)maxDuration));
    seekbar.setRangeMin((minTrimDuration * 100f) / (float) maxDuration);
    mediaMetadataRetriever.release();
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) MediaMetadataRetriever(android.media.MediaMetadataRetriever)

Example 48 with WritableMap

use of com.facebook.react.bridge.WritableMap in project react-native-android-video-editor by RZulfikri.

the class VideoTrim method setupListener.

/**
     *  Function to setup Gesture listener
     */
private void setupListener() {
    /*
            Listener to scrool video preview timeline when video timeline
            more than layout width
         */
    videoTimeline.setOnTouchListener(new OnTouchListener() {

        @Override
        public boolean onTouch(View v, final MotionEvent event) {
            switch(event.getAction()) {
                // Detect Touch Down
                case MotionEvent.ACTION_DOWN:
                    move1 = (int) event.getX();
                    break;
                // Detect when gesture move
                case MotionEvent.ACTION_MOVE:
                    // Detect if video preview timeline posision equal than layout start
                    if (videoTimeline.getCanvasWidthStart() == 0) {
                        // Detect when scroll to left
                        if ((int) event.getX() <= move1) {
                            final Thread thread = new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    if (isScrollRight && !isScrollLeft) {
                                        move4 = 0;
                                    }
                                    move2 = (int) event.getX();
                                    if (Math.abs((move1 - move2) - move4) < (videoTimeline.getCanvasWidth() - usedWidth)) {
                                        move3 = move1 - move2;
                                        move5 = move5 + (move3 - move4);
                                        videoTimeline.setXPos(-Math.abs(move5));
                                        canvasSeekPos = (move5 * duration) / (videoTimeline.getCanvasWidth() + Math.abs(videoTimeline.getCanvasWidthStart()));
                                        // videoPlayerControl.setStartPos(rangeSeekPos + canvasSeekPos);
                                        // videoPlayerControl.setEndPos(rangeSeekEndPos+canvasSeekPos);
                                        WritableMap event = Arguments.createMap();
                                        event.putInt(Events.START_POS, rangeSeekPos + canvasSeekPos);
                                        WritableMap event2 = Arguments.createMap();
                                        event2.putInt(Events.END_POS, rangeSeekEndPos + canvasSeekPos);
                                        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_START_POS.toString(), event);
                                        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event2);
                                        move4 = move3;
                                        isScrollRight = false;
                                        isScrollLeft = true;
                                    }
                                }
                            });
                            thread.run();
                        }
                    } else // Detect if video preview timeline posision less than layout start
                    if (videoTimeline.getCanvasWidthStart() < 0) {
                        // Detect when scroll to left
                        if ((int) event.getX() <= move1) {
                            final Thread thread = new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    if (isScrollRight && !isScrollLeft) {
                                        move4 = 0;
                                    }
                                    move2 = (int) event.getX();
                                    if (Math.abs((move1 - move2) - move4) < (videoTimeline.getCanvasWidth() - usedWidth)) {
                                        move3 = move1 - move2;
                                        move5 = move5 + (move3 - move4);
                                        videoTimeline.setXPos(-Math.abs(move5));
                                        canvasSeekPos = (move5 * duration) / (videoTimeline.getCanvasWidth() + Math.abs(videoTimeline.getCanvasWidthStart()));
                                        // videoPlayerControl.setStartPos(rangeSeekPos + canvasSeekPos);
                                        // videoPlayerControl.setEndPos(rangeSeekEndPos+canvasSeekPos);
                                        WritableMap event = Arguments.createMap();
                                        event.putInt(Events.START_POS, rangeSeekPos + canvasSeekPos);
                                        WritableMap event2 = Arguments.createMap();
                                        event2.putInt(Events.END_POS, rangeSeekEndPos + canvasSeekPos);
                                        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_START_POS.toString(), event);
                                        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event2);
                                        move4 = move3;
                                        isScrollRight = false;
                                        isScrollLeft = true;
                                    }
                                }
                            });
                            thread.run();
                        } else // Detect when scroll to right
                        if ((int) event.getX() > move1) {
                            final Thread thread = new Thread(new Runnable() {

                                @Override
                                public void run() {
                                    if (!isScrollRight && isScrollLeft) {
                                        move4 = 0;
                                    }
                                    move2 = (int) event.getX();
                                    if (Math.abs((move5 - ((move2 - move1) - move4))) < Math.abs(videoTimeline.getCanvasWidthStart())) {
                                        move3 = move2 - move1;
                                        move5 = move5 - (move3 - move4);
                                        videoTimeline.setXPos(-Math.abs(move5));
                                        canvasSeekPos = (move5 * duration) / (videoTimeline.getCanvasWidth() + Math.abs(videoTimeline.getCanvasWidthStart()));
                                        // videoPlayerControl.setStartPos(rangeSeekPos + canvasSeekPos);
                                        // videoPlayerControl.setEndPos(rangeSeekEndPos+canvasSeekPos);
                                        WritableMap event = Arguments.createMap();
                                        event.putInt(Events.START_POS, rangeSeekPos + canvasSeekPos);
                                        WritableMap event2 = Arguments.createMap();
                                        event2.putInt(Events.END_POS, rangeSeekEndPos + canvasSeekPos);
                                        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_START_POS.toString(), event);
                                        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event2);
                                        move4 = move3;
                                        isScrollRight = true;
                                        isScrollLeft = false;
                                    }
                                }
                            });
                            thread.start();
                        }
                    }
                    break;
                case MotionEvent.ACTION_UP:
                    move4 = 0;
                    break;
                default:
                    break;
            }
            return true;
        }
    });
    /*
             Listener for seekbar control (Seekbar button left and right)
             index (0) = button seek left
             index (1) = button seek right
             value = value of seekButton (0 - 100)
         */
    seekbar.addOnRangeSeekBarListener(new OnRangeSeekBarListener() {

        @Override
        public void onCreate(CustomRangeSeekBarView customRangeSeekBarView, int index, float value) {
        }

        @Override
        public void onSeek(CustomRangeSeekBarView customRangeSeekBarView, int index, float value) {
            if (index == 0) {
                rangeSeekPos = (int) ((value / 100) * maxDuration);
                canvasSeekPos = (move5 * duration) / (videoTimeline.getCanvasWidth() + Math.abs(videoTimeline.getCanvasWidthStart()));
                // videoPlayerControl.setStartPos(rangeSeekPos + canvasSeekPos);
                WritableMap event = Arguments.createMap();
                event.putInt(Events.START_POS, rangeSeekPos + canvasSeekPos);
                eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_START_POS.toString(), event);
            } else {
                rangeSeekEndPos = (int) (maxDuration * (value / 100));
                // videoPlayerControl.setEndPos(rangeSeekEndPos+canvasSeekPos);
                WritableMap event = Arguments.createMap();
                event.putInt(Events.END_POS, rangeSeekEndPos + canvasSeekPos);
                eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_END_POS.toString(), event);
            }
        }

        @Override
        public void onSeekStart(CustomRangeSeekBarView customRangeSeekBarView, int index, float value) {
        }

        @Override
        public void onSeekStop(CustomRangeSeekBarView customRangeSeekBarView, int index, float value) {
        }
    });
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap) View(android.view.View) MotionEvent(android.view.MotionEvent)

Example 49 with WritableMap

use of com.facebook.react.bridge.WritableMap in project react-native-android-video-editor by RZulfikri.

the class VideoSurfaceView method paused.

public void paused(boolean isPaused) {
    if (isPaused && mMediaPlayer.isPlaying()) {
        mMediaPlayer.pause();
        WritableMap event = Arguments.createMap();
        event.putBoolean(Events.VIDEO_PLAYER_STATUS, false);
        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_VIDEO_PLAYER_STATUS.toString(), event);
    }
    if (!isPaused && !mMediaPlayer.isPlaying()) {
        mMediaPlayer.start();
        WritableMap event = Arguments.createMap();
        event.putBoolean(Events.VIDEO_PLAYER_STATUS, true);
        eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_VIDEO_PLAYER_STATUS.toString(), event);
    }
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap)

Example 50 with WritableMap

use of com.facebook.react.bridge.WritableMap in project react-native-android-video-editor by RZulfikri.

the class VideoSurfaceView method onHostPause.

@Override
public void onHostPause() {
    //         Log.e("DEBUG", "PAUSE");
    if (mMediaPlayer != null) {
        if (mMediaPlayer.isPlaying()) {
            mMediaPlayer.pause();
            WritableMap event = Arguments.createMap();
            event.putBoolean(Events.VIDEO_PLAYER_STATUS, false);
            eventEmitter.receiveEvent(getId(), EventsEnum.EVENT_GET_VIDEO_PLAYER_STATUS.toString(), event);
        }
        // mMediaPlayer.release();
        // mMediaPlayer = null;
        onPaused = true;
    }
}
Also used : WritableMap(com.facebook.react.bridge.WritableMap)

Aggregations

WritableMap (com.facebook.react.bridge.WritableMap)54 ReactContext (com.facebook.react.bridge.ReactContext)5 ThemedReactContext (com.facebook.react.uimanager.ThemedReactContext)4 Intent (android.content.Intent)3 WritableNativeMap (com.facebook.react.bridge.WritableNativeMap)3 RCTEventEmitter (com.facebook.react.uimanager.events.RCTEventEmitter)3 IOException (java.io.IOException)3 BroadcastReceiver (android.content.BroadcastReceiver)2 Context (android.content.Context)2 IntentFilter (android.content.IntentFilter)2 MediaMetadataRetriever (android.media.MediaMetadataRetriever)2 Bundle (android.os.Bundle)2 View (android.view.View)2 Callback (com.facebook.react.bridge.Callback)2 ReactApplicationContext (com.facebook.react.bridge.ReactApplicationContext)2 ReadableMap (com.facebook.react.bridge.ReadableMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 JSONArray (org.json.JSONArray)2 JSONObject (org.json.JSONObject)2