1

我正在尝试在 android 中实现 BrightCove Exoplayer。我能够成功实现播放单个视频。现在我正在尝试使用 Exoplayer 播放播放列表。播放列表中的第一个视频播放,在第一个视频结束时,播放器不播放播放列表中的下一个视频。它再次显示第一个视频的开头;如果我按下播放按钮,第一个视频会再次播放。我想实现一个接一个地连续播放播放列表中的所有视频。我错过了什么吗?我在下面发布我的代码:

主要活动:

package com.brightcove.player.samples.exoplayer.basic;

import android.os.Bundle;
import android.util.Log;

import com.brightcove.player.edge.VideoListener;
import com.brightcove.player.event.EventEmitter;
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 com.brightcove.player.media.Catalog;
import com.brightcove.player.media.PlaylistListener;

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

        Catalog catalog = new Catalog("MyToken");

        catalog.findPlaylistByReferenceID("MyPlaylistReference", new PlaylistListener() {
            @Override
            public void onPlaylist(Playlist playlist) {
                brightcoveVideoView.addAll(playlist.getVideos());
                //brightcoveVideoView.start();
            }

            @Override
            public void onError(String s) {
                throw new RuntimeException(s);
            }
        });

        if (savedInstanceState != null) {
            Log.v(TAG, "Restoring saved position");
        } else {
            Log.v(TAG, "No saved state");
        }
    }
}
4

1 回答 1

0

我有同样的问题,你可以在那里找到我的解决方案:在你的“onStateChanged”方法上释放实际的播放器,然后再次准备一个新的播放器,你将能够播放一个新视频(在你的 preparePlayer 上记得更改视频 URL)

@Override
    public void onStateChanged(boolean playWhenReady, int playbackState) {
        switch (playbackState) {
            case ExoPlayer.STATE_BUFFERING:
                text += "buffering";
                break;
            case ExoPlayer.STATE_ENDED:
                if (playlistPosition < playlist.size() - 1) {
                    playlistPosition++;
                    releasePlayer();
                    preparePlayer();
                }
                text += "ended";
                break;
            default:
                text += "unknown";
                break;
        }
    }

 private void preparePlayer() {
        if (player == null) {
            player = new DemoPlayer(getRendererBuilder(playlist.get(playlistPosition).type)); [...]

我希望这可以帮助你

于 2015-09-16T10:45:34.033 回答