我正在尝试在android中实现BrightCove Exoplayer。我能够成功实现播放个人视频。现在我正在尝试使用Exoplayer播放播放列表。播放列表中的第一个视频播放,在第一个视频结束时,播放器不播放播放列表中的下一个视频。它再次显示了第一个视频的开头;如果按下播放按钮,则会再次播放第一个视频。我希望一个接一个地连续播放播放列表中的所有视频。我错过了什么吗?我在下面发布我的代码:
MainActivity:
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");
}
}
}
答案 0 :(得分:0)
我有同样的问题,你可以在那里找到我的解决方案: 在你的“onStateChanged”方法发布实际播放器然后再准备一个新的,你将能够播放一个新的视频(在你的preparePlayer上记得改变视频网址)
@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)); [...]
我希望能帮到你