Playing one video after another in android Broghtcove Exoplayer implementation

左心房为你撑大大i 提交于 2019-12-23 01:06:23

问题


I am trying to play one video after another using Brightcove Exoplayer in android. I am able to catch the eventtype "completed" at the end of the first video and then I am trying to play the next video. But its stuck at the end of the first video. The second video is not playing. I am getting a NullPointerException. What am I doing wrong? This is my code:

public class MainActivity extends BrightcovePlayer {

    private final String TAG = this.getClass().getSimpleName();

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        setContentView(R.layout.activity_main);
        brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
        super.onCreate(savedInstanceState);

        EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
        final Catalog catalog = new Catalog(eventEmitter, "accountID", "policy");

        catalog.findVideoByID("videoID1", new VideoListener() {

            @Override
            public void onVideo(Video video) {
                Log.v(TAG, "onVideo: video = " + video);
                brightcoveVideoView.add(video);
                brightcoveVideoView.start();
            }


        });

        eventEmitter.on("completed", new EventListener() {
            @Override
            public void processEvent(Event event) {

               catalog.findVideoByID("videoID2", new VideoListener() {

                    @Override
                    public void onVideo(Video video) {
                        brightcoveVideoView.clear();
                        brightcoveVideoView.stopPlayback();
                        brightcoveVideoView.seekTo(0);
                        Log.v(TAG, "onVideo: video = " + video);
                        brightcoveVideoView.add(video);
                        brightcoveVideoView.start();
                    }


                });
            }
        });


        // Log whether or not instance state in non-null.
        if (savedInstanceState != null) {
            Log.v(TAG, "Restoring saved position");
        } else {
            Log.v(TAG, "No saved state");
        }
    }
}

Logcat:

09-16 18:49:22.960  32438-32438/com.brightcove.player.samples.exoplayer.basic D/PlayButtonController﹕ Process event: completed.
09-16 18:49:22.960  32438-32438/com.brightcove.player.samples.exoplayer.basic V/AbstractButtonController﹕ Start of sync update: text = ; description = Pause.
09-16 18:49:22.970  32438-32438/com.brightcove.player.samples.exoplayer.basic V/AbstractButtonController﹕ End of sync update: text = ; description = Play.
09-16 18:49:22.970  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ didPause { playheadPosition: 0 }
09-16 18:49:22.980  32438-32438/com.brightcove.player.samples.exoplayer.basic D/PlayButtonController﹕ Process event: didPause.
09-16 18:49:22.980  32438-32438/com.brightcove.player.samples.exoplayer.basic V/AbstractButtonController﹕ Start of sync update: text = ; description = Play.
09-16 18:49:22.980  32438-32438/com.brightcove.player.samples.exoplayer.basic V/AbstractButtonController﹕ End of sync update: text = ; description = Play.
09-16 18:49:22.980  32438-32438/com.brightcove.player.samples.exoplayer.basic V/BaseVideoView﹕ onMeasure: width = 1024, height = 550, videoWidth = 1024, videoHeight = 576, widthMode = MeasureSpec.EXACTLY, heightMode = MeasureSpec.EXACTLY
09-16 18:49:22.990    32438-369/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.MARVELL.VIDEO.HW.CODA7542DECODER] Now Flushing
09-16 18:49:22.990    32438-369/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.MARVELL.VIDEO.HW.CODA7542DECODER] Now Executing
09-16 18:49:22.990    32438-372/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.SEC.aac.dec] Now Flushing
09-16 18:49:22.990    32438-372/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.SEC.aac.dec] Now Executing
09-16 18:49:22.990  32438-32438/com.brightcove.player.samples.exoplayer.basic V/BaseVideoView﹕ onLayout: changed = false, left = 0, top = 0, right = 1024, bottom = 550
09-16 18:49:23.000  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ onLoadStarted: sourceId: 0, length: -1, type: 1, trigger: 0, bitrate: 1351359, mediaStartTimeMs: 0, mediaEndTimeMs: 10000
09-16 18:49:23.250  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ didHideMediaControls { }
09-16 18:49:23.480  32438-32438/com.brightcove.player.samples.exoplayer.basic V/BaseVideoView﹕ onMeasure: width = 1024, height = 550, videoWidth = 1024, videoHeight = 576, widthMode = MeasureSpec.EXACTLY, heightMode = MeasureSpec.EXACTLY
09-16 18:49:23.480  32438-32438/com.brightcove.player.samples.exoplayer.basic V/BaseVideoView﹕ onLayout: changed = false, left = 0, top = 0, right = 1024, bottom = 550
09-16 18:49:26.103    32438-336/com.brightcove.player.samples.exoplayer.basic D/dalvikvm﹕ GC_FOR_ALLOC freed 712K, 35% free 6530K/9900K, paused 28ms, total 28ms
09-16 18:49:26.573    32438-336/com.brightcove.player.samples.exoplayer.basic D/dalvikvm﹕ GC_FOR_ALLOC freed 8K, 34% free 6780K/10160K, paused 28ms, total 28ms
09-16 18:49:26.804  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ onLoadCompleted: sourceId: 0, bytesLoaded: 1984152, type: 1, bitrate: 1351359, startTime: 0, endTime: 10000
09-16 18:49:26.804  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ onLoadStarted: sourceId: 0, length: -1, type: 1, trigger: 0, bitrate: 1351359, mediaStartTimeMs: 10000, mediaEndTimeMs: 20000
09-16 18:49:27.134    32438-336/com.brightcove.player.samples.exoplayer.basic D/dalvikvm﹕ GC_FOR_ALLOC freed 30K, 33% free 7037K/10420K, paused 22ms, total 22ms
09-16 18:49:27.514    32438-336/com.brightcove.player.samples.exoplayer.basic D/dalvikvm﹕ GC_FOR_ALLOC freed 5K, 32% free 7293K/10680K, paused 20ms, total 20ms
09-16 18:49:27.855    32438-336/com.brightcove.player.samples.exoplayer.basic D/dalvikvm﹕ GC_FOR_ALLOC freed 3K, 31% free 7549K/10940K, paused 29ms, total 29ms
09-16 18:49:28.555  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ onLoadCompleted: sourceId: 0, bytesLoaded: 1221624, type: 1, bitrate: 1351359, startTime: 10000, endTime: 20000
09-16 18:49:28.555  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ onLoadStarted: sourceId: 0, length: -1, type: 1, trigger: 0, bitrate: 1351359, mediaStartTimeMs: 20000, mediaEndTimeMs: 30000
09-16 18:49:33.590  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ onLoadCompleted: sourceId: 0, bytesLoaded: 1779232, type: 1, bitrate: 1351359, startTime: 20000, endTime: 30000
09-16 18:49:42.289  32438-32438/com.brightcove.player.samples.exoplayer.basic D/BrightcoveMediaController﹕ Processing onTouch for view: com.brightcove.player.view.BrightcoveExoPlayerVideoView{41dff550 VFE...C. .F...... 0,0-1024,550 #7f0b0000 app:id/brightcove_video_view}, with event: MotionEvent { action=ACTION_DOWN, id[0]=0, x[0]=452.44183, y[0]=261.5192, toolType[0]=TOOL_TYPE_FINGER, buttonState=0, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=9956540, downTime=9956540, deviceId=3, source=0x1002 }.
09-16 18:49:42.289  32438-32438/com.brightcove.player.samples.exoplayer.basic D/BrightcoveMediaController﹕ The control bar is hidden, show the media controls...
09-16 18:49:42.289  32438-32438/com.brightcove.player.samples.exoplayer.basic I/BaseVideoView﹕ onTouchEvent
09-16 18:49:42.289  32438-32438/com.brightcove.player.samples.exoplayer.basic D/BrightcoveShowHideController﹕ Showing the media controls.  They will be hidden in 3000 milliseconds using animation style: FADE.
09-16 18:49:42.299  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ showMediaControls { }
09-16 18:49:42.299  32438-32438/com.brightcove.player.samples.exoplayer.basic D/BrightcoveShowHideController﹕ Showing the media controls.  They will be hidden in 3000 milliseconds using animation style: FADE.
09-16 18:49:42.299  32438-32438/com.brightcove.player.samples.exoplayer.basic V/BaseVideoView﹕ onMeasure: width = 1024, height = 550, videoWidth = 1024, videoHeight = 576, widthMode = MeasureSpec.EXACTLY, heightMode = MeasureSpec.EXACTLY
09-16 18:49:42.299  32438-32438/com.brightcove.player.samples.exoplayer.basic V/BaseVideoView﹕ onLayout: changed = false, left = 0, top = 0, right = 1024, bottom = 550
09-16 18:49:42.309  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ didShowMediaControls { controlsHeight: 64 }
09-16 18:49:42.309  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ didShowMediaControls { controlsHeight: 64 }
09-16 18:49:45.302  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ didHideMediaControls { }
09-16 18:49:45.512  32438-32438/com.brightcove.player.samples.exoplayer.basic V/BaseVideoView﹕ onMeasure: width = 1024, height = 550, videoWidth = 1024, videoHeight = 576, widthMode = MeasureSpec.EXACTLY, heightMode = MeasureSpec.EXACTLY
09-16 18:49:45.512  32438-32438/com.brightcove.player.samples.exoplayer.basic V/BaseVideoView﹕ onLayout: changed = false, left = 0, top = 0, right = 1024, bottom = 550
09-16 18:49:49.876    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ response: {"description":null,"poster_sources":[{"src":"http://brightcove.vo.llnwd.net/v1/unsecured/media/accountID/201508/3522/accountID_4446404273001_videoID2-vs.jpg?pubId=accountID&videoId=videoID2"}],"tags":[],"cue_points":[],"custom_fields":{},"account_id":"accountID","sources":[{"avg_bitrate":997000,"width":640,"duration":134000,"size":16791137,"stream_name":"mp4:accountID/accountID_4446405618001_videoID2.mp4&1442415600000&782ccdd093adf6c97a4d9bc7d2962a49","codec":"H264","asset_id":"4446405618001","container":"MP4","height":360,"app_name":"rtmp://brightcove.fcod.llnwd.net/a500/e1/uds/rtmp/ondemand"},{"avg_bitrate":997000,"width":640,"src":"http://brightcove.vo.llnwd.net/e1/uds/pd/accountID/accountID_4446405618001_videoID2.mp4?pubId=accountID&videoId=videoID2","size":16791137,"height":360,"duration":134000,"container":"MP4","codec":"H264","asset_id":"4446405618001"},{"avg_bitrate":514000,"width":480,"duration":134000,"size":8664661,"stream_name":"mp4:accountID/accountID_4446405652001_videoID2.mp4&1442415600000&782ccdd093adf6c97a4d9bc7d2962a49","codec":"H264","asset_id":"4446405652001","container":"MP4","height":270,"app_name":"rtmp://brightcove.fcod.llnwd.net/a500/e1/uds/rtmp/ondemand"},{"avg_bitrate":514000,"width":480,"src":"http://brightcove.vo.llnwd.net/e1/uds/pd/accountID/accountID_4446405652001_videoID2.mp4?pubId=accountID&videoId=videoID2","size":8664661,"height":270,"duration":134000,"container":"MP4","codec":"H264","asset_id":"4446405652001"},{"avg_bitrate":1831000,"width":960,"duration":134000,"size":30751569,"stream_name":"mp4:accountID/accountID_4446407440001_videoID2.mp4&1442415600000&782ccdd093adf6c97a4d9bc7d2962a49","codec":"H264","asset_id":"4446407440001","container":"MP4","height":540,"app_name":"rtmp://brightcove.fcod.llnwd.net/a500/e1/uds/rtmp/ondemand"},{"avg_bitrate":1831000,"width":960,"src":"http://brightcove.vo.llnwd.net/e1/uds/pd/accountID/accountID_4446407440001_videoID2.mp4?pubId=accountID&videoId=videoID2","size":30751569,"height":540,"duration":134000,"container":"MP4","codec":"H264","asset_id":"4446407440001"},{"type":"application/x-mpegURL","src":"http://c.brightcove.com/services/mobile/streaming/index/master.m3u8?videoId=videoID2&pubId=accountID","container":"M2TS","codec":"H264"},{"type":"application/x-mpegURL","src":"https://secure.brightcove.com/services/mobile/streaming/index/master.m3u8?videoId=videoID2&pubId=accountID&secure=true","container":"M2TS","codec":"H264"}],"name":"Control And Coordination (Scared - X+Y).mp4","reference_id":null,"long_description":null,"duration":134000,"published_at":"2015-08-27T21:46:17.492Z","text_tracks":[],"updated_at":"2015-08-27T21:46:17.492Z","thumbnail":"http://brightcove.vo.llnwd.net/v1/unsecured/media/accountID/201508/3522/accountID_4446404304001_videoID2-th.jpg?pubId=accountID&videoId=videoID2","poster":"http://brightcove.vo.llnwd.net/v1/unsecured/media/accountID/201508/3522/accountID_4446404273001_videoID2-vs.jpg?pubId=accountID&videoId=videoID2","link":null,"id":"videoID2","ad_keys":null,"thumbnail_sources":[{"src":"http://brightcove.vo.llnwd.net/v1/unsecured/media/accountID/201508/3522/accountID_4446404304001_videoID2-th.jpg?pubId=accountID&videoId=videoID2"}],"created_at":"2015-08-27T07:11:46.648Z"}
09-16 18:49:49.876    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ code: 200
09-16 18:49:49.876    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ message: OK
09-16 18:49:49.896    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ issuing GET request: https://metrics.brightcove.com/tracker?platform=android-native-sdk&device_os_version=4.4.2&range=27..28&device_type=tablet&destination=bcsdk%3A%2F%2FExoPlayer+Sample+App%2Fcom.brightcove.player.samples.exoplayer.basic&device_os=android&time=1442409562964&platform_version=4.4.2&event=video_engagement&domain=videocloud&account=accountID&device_cpu=armeabi-v7a&video_duration=30&video=videoID1, headers: {}
09-16 18:49:49.906  32438-32438/com.brightcove.player.samples.exoplayer.basic D/BaseVideoView﹕ Seeking to 0
09-16 18:49:49.906  32438-32438/com.brightcove.player.samples.exoplayer.basic V/MainActivity﹕ onVideo: video = Video{name: "Control And Coordination (Scared - X+Y).mp4", sourceCollections: 2, cuePoints: 0}
09-16 18:49:49.906  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ willChangeVideo { currentVideo: null nextVideo: null index: 0 uuid: 96c2c14b-16b8-41fb-be17-00a3ec5fd907 }
09-16 18:49:49.906  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ didChangeList { list: [Video{name: "Control And Coordination (Scared - X+Y).mp4", sourceCollections: 2, cuePoints: 0}] }
09-16 18:49:49.906  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ stop { playheadPosition: 0 }
09-16 18:49:49.906  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ ExoPlayerOnStopListener:
09-16 18:49:49.906  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ destroyPlayer: exoPlayer = com.google.android.exoplayer.ExoPlayerImpl@41f8c768
09-16 18:49:49.906  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ stopUpdater: null
09-16 18:49:49.906    32438-369/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.MARVELL.VIDEO.HW.CODA7542DECODER] Now Executing->Idle
09-16 18:49:49.916    32438-369/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.MARVELL.VIDEO.HW.CODA7542DECODER] Now Idle->Loaded
09-16 18:49:49.926    32438-369/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.MARVELL.VIDEO.HW.CODA7542DECODER] Now Loaded
09-16 18:49:49.946    32438-369/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.MARVELL.VIDEO.HW.CODA7542DECODER] Now uninitialized
09-16 18:49:49.956    32438-372/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.SEC.aac.dec] Now Executing->Idle
09-16 18:49:49.966    32438-372/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.SEC.aac.dec] Now Idle->Loaded
09-16 18:49:49.966    32438-372/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.SEC.aac.dec] Now Loaded
09-16 18:49:49.966    32438-372/com.brightcove.player.samples.exoplayer.basic I/ACodec﹕ [OMX.SEC.aac.dec] Now uninitialized
09-16 18:49:49.966  32438-32438/com.brightcove.player.samples.exoplayer.basic D/PlayButtonController﹕ Process event: stop.
09-16 18:49:49.966  32438-32438/com.brightcove.player.samples.exoplayer.basic V/AbstractButtonController﹕ Start of sync update: text = ; description = Play.
09-16 18:49:49.966  32438-32438/com.brightcove.player.samples.exoplayer.basic V/AbstractButtonController﹕ End of sync update: text = ; description = Play.
09-16 18:49:49.966  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ seekTo { seekPosition: 0 }
09-16 18:49:49.966  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ ExoPlayerOnSeekListener:
09-16 18:49:49.966  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ didChangeList { list: [Video{name: "Control And Coordination (Scared - X+Y).mp4", sourceCollections: 2, cuePoints: 0}] }
09-16 18:49:49.966  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ willChangeVideo { currentVideo: Video{name: "Control And Coordination (Scared - X+Y).mp4", sourceCollections: 2, cuePoints: 0} nextVideo: Video{name: "Control And Coordination (Scared - X+Y).mp4", sourceCollections: 2, cuePoints: 0} index: 0 uuid: 07a14bbe-6920-404b-a3d6-a74459cde927 }
09-16 18:49:49.976  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ setSource { }
09-16 18:49:49.976  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ ExoPlayerOnSetSourceListener
09-16 18:49:49.976  32438-32438/com.brightcove.player.samples.exoplayer.basic V/ExoPlayerVideoDisplayComponent﹕ destroyPlayer: exoPlayer = null
09-16 18:49:49.976  32438-32438/com.brightcove.player.samples.exoplayer.basic E/com.brightcove.player.event.EventEmitterImpl@41e01b08﹕ processEvent() threw a throwable.
    java.lang.NullPointerException
            at com.brightcove.player.display.ExoPlayerVideoDisplayComponent.openVideo(ExoPlayerVideoDisplayComponent.java:425)
            at com.brightcove.player.display.ExoPlayerVideoDisplayComponent$ExoPlayerOnSetSourceListener.processEvent(ExoPlayerVideoDisplayComponent.java:533)
            at com.brightcove.player.event.EventEmitterImpl.invokeListenersForEventType(EventEmitterImpl.java:457)
            at com.brightcove.player.event.EventEmitterImpl.invokeListenersForEvent(EventEmitterImpl.java:428)
            at com.brightcove.player.event.EventEmitterImpl.access$300(EventEmitterImpl.java:41)
            at com.brightcove.player.event.EventEmitterImpl$1.handleMessage(EventEmitterImpl.java:73)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:146)
            at android.app.ActivityThread.main(ActivityThread.java:5598)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1283)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1099)
            at dalvik.system.NativeStart.main(Native Method)
09-16 18:49:49.976  32438-32438/com.brightcove.player.samples.exoplayer.basic D/MainActivity﹕ didStop { playheadPosition: 0 }
09-16 18:49:50.226    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ response: GIF89a������������������!�����������,��������������D��;
09-16 18:49:50.226    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ code: 200
09-16 18:49:50.226    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ message: OK
09-16 18:49:50.236    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ issuing GET request: https://metrics.brightcove.com/tracker?device_os=android&platform=android-native-sdk&device_os_version=4.4.2&time=1442409562964&platform_version=4.4.2&event=video_complete&device_type=tablet&domain=videocloud&account=accountID&device_cpu=armeabi-v7a&video_duration=30&video=videoID1&destination=bcsdk%3A%2F%2FExoPlayer+Sample+App%2Fcom.brightcove.player.samples.exoplayer.basic, headers: {}
09-16 18:49:50.477    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ response: GIF89a������������������!�����������,��������������D��;
09-16 18:49:50.477    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ code: 200
09-16 18:49:50.477    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ message: OK
09-16 18:49:50.487    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ issuing GET request: https://metrics.brightcove.com/tracker?device_os=android&platform=android-native-sdk&device_os_version=4.4.2&time=1442409589981&platform_version=4.4.2&event=video_impression&device_type=tablet&domain=videocloud&account=accountID&device_cpu=armeabi-v7a&video=videoID2&destination=bcsdk%3A%2F%2FExoPlayer+Sample+App%2Fcom.brightcove.player.samples.exoplayer.basic, headers: {}
09-16 18:49:50.727    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ response: GIF89a������������������!�����������,��������������D��;
09-16 18:49:50.727    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ code: 200
09-16 18:49:50.727    32438-332/com.brightcove.player.samples.exoplayer.basic D/HttpService﹕ message: OK

回答1:


A little late but considering no answers...

Messing with the video list (i.e. adding/removing Video objects dynamically in a BC player - any which derives from BaseVideoView) will derail you quickly and will make you either 1) weep or 2) scream at innocent bystanders :)

I have my own theory but it's irrelevant to the question.

We solved the problems by dynamically stopping/destroying the completed player and then adding a brand new one for the next video to play.

Which means:

  • keep your video list in your activity/fragment/view container
  • when a video is over, ensure you clear resources and then remove physically the player view from the view list
  • show a preloader or some nice animation
  • add or inflate another exo player instance (use a Runnable to avoid above preloader freezing while preparing) and then load the next video
  • hide preloader and play the video when event is dispatched for video is ready to play

This works quite well, view swapping is almost immediate - almost unnoticeable.




回答2:


Instead of using

eventEmitter.on("completed", new EventListener() {

Use the OnCompletionListener on the BrightcoveExoPlayerVideoView object. Here is an example of playing video one after another from a playlist. First, it gets the play list by id using com.brightcove.player.media.Catalog then play the next video when the previous one is completed using com.brightcove.player.edge.Catalog

import android.media.MediaPlayer;
import android.os.Bundle;
import android.util.Log;
import com.brightcove.player.edge.VideoListener;
import com.brightcove.player.event.EventEmitter;
import com.brightcove.player.media.PlaylistListener;
import com.brightcove.player.model.Playlist;
import com.brightcove.player.model.Video;
import com.brightcove.player.view.BrightcoveExoPlayerVideoView;
import com.brightcove.player.view.BrightcovePlayer;
import java.util.List;
public class MainActivity extends BrightcovePlayer {
    private final String TAG = this.getClass().getSimpleName();
    private List<Video> videos;
    private int videoIndex = 0;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_main);
        brightcoveVideoView = (BrightcoveExoPlayerVideoView) findViewById(R.id.brightcove_video_view);
        super.onCreate(savedInstanceState);

        //Get the playlist
        com.brightcove.player.media.Catalog mediaCatalog = new com.brightcove.player.media.Catalog(getString(R.string.brightcove_token));
        mediaCatalog.findPlaylistByID(getString(R.string.playListId), new PlaylistListener() {
            @Override
            public void onPlaylist(Playlist playlist) {
                videos = playlist.getVideos();
                if (videos != null && videos.size() > 0)
                    playVideo(videos.get(videoIndex));

            }

            @Override
            public void onError(String s) {
                Log.d(TAG, "onCreate() findPlaylistByID() onError()" + s);
            }
        });

    }

    private void playVideo(Video video) {
        if (video == null) return;

        //Play the video
        EventEmitter eventEmitter = brightcoveVideoView.getEventEmitter();
        com.brightcove.player.edge.Catalog catalog = new com.brightcove.player.edge.Catalog(eventEmitter, getString(R.string.account), getString(R.string.policy));
        catalog.findVideoByID(video.getId(), new VideoListener() {
            @Override
            public void onVideo(Video video) {
                brightcoveVideoView.add(video);
                brightcoveVideoView.start();
            }
        });

        //Play the next video in the list when the current one is completed
        brightcoveVideoView.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                if (videoIndex == videos.size()) {
                    videoIndex = 0;
                } else {
                    videoIndex++;
                }
                playVideo(videos.get(videoIndex));
            }
        });
    }

}

The activty_main.xml

<merge xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context=".MainActivity" >

    <com.brightcove.player.view.BrightcoveExoPlayerVideoView
        android:id="@+id/brightcove_video_view"
        android:layout_width="match_parent"
        android:layout_height="280dp"
        android:layout_gravity="center_horizontal|top"/>

</merge>

For string.xml in the value folder, fill in your credentials, tokens, playlist id, etc.

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <!-- Application name -->
    <string name="app_name">ExoPlayer Sample App</string>

    <!-- A sample Brightcove Edge Account ID -->
    <string name="account"></string>

    <!-- A sample Brightcove Edge Policy Key -->
    <string name="policy"></string>

    <string name="playListId"></string>

    <string name="brightcove_token"></string>

</resources>



回答3:


You don't need to call the stopPlayback and seek after calling the clear method of brightcove video view. The better way is to clear,add and start with the new video object

brightcoveVideoView.clear();
brightcoveVideoView.add(video);
brightcoveVideoView.start();


来源:https://stackoverflow.com/questions/32610116/playing-one-video-after-another-in-android-broghtcove-exoplayer-implementation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!