1

我正在尝试在 android 中使用 Brightcove Exoplayer 播放一个又一个视频。我能够在第一个视频的结尾捕捉到事件类型“已完成”,然后我正在尝试播放下一个视频。但它卡在第一个视频的末尾。第二个视频没有播放。我得到一个 NullPointerException。我究竟做错了什么?这是我的代码:

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");
        }
    }
}

日志猫:

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
4

3 回答 3

1

而不是使用

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

在 BrightcoveExoPlayerVideoView 对象上使用 OnCompletionListener。这是一个从播放列表中依次播放视频的示例。首先,它使用 com.brightcove.player.media.Catalog 通过 id 获取播放列表,然后在上一个视频完成时使用 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));
            }
        });
    }

}

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>

对于 value 文件夹中的 string.xml,填写您的凭据、令牌、播放列表 ID 等。

<?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>
于 2016-01-18T20:45:47.023 回答
1

调用 brightcove 视频视图的 clear 方法后,无需调用 stopPlayback 和 seek。更好的方法是清除、添加并从新的视频对象开始

brightcoveVideoView.clear();
brightcoveVideoView.add(video);
brightcoveVideoView.start();
于 2016-06-06T07:11:38.663 回答
1

有点晚了,但考虑没有答案......

弄乱视频列表(即在 BC 播放器中动态添加/删除Video对象 - 任何从BaseVideoView派生的对象)会很快让你脱轨,并且会让你 1)哭泣或 2)对无辜的旁观者尖叫 :)

我有自己的理论,但这与问题无关。

我们通过动态停止/销毁已完成的播放器,然后为下一个要播放的视频添加一个全新的播放器来解决问题。

意思是:

  • 将您的视频列表保存在您的活动/片段/视图容器中
  • 当视频结束时,确保您清除资源,然后从视图列表中物理删除播放器视图
  • 显示预加载器或一些不错的动画
  • 添加或膨胀另一个 exo 播放器实例(使用 Runnable 以避免在准备时预加载器冻结),然后加载下一个视频
  • 当为视频发送事件准备好播放时隐藏预加载器并播放视频

这很有效,视图交换几乎是立即的 - 几乎不引人注意。

于 2015-11-20T22:17:35.417 回答