如何在 ExoPlayer.STATE_ENDED 后重新启动 Exoplayer 上的视频
How to restart video on Exoplayer after ExoPlayer.STATE_ENDED
我在 Exoplayer 的基础上使用 DemoPlayer。
我想 restart/replay 视频从某些用户操作 开始 ExoPlayer.STATE_ENDED 已发送。
之后我尝试使用 seekTo(0)
和 mPlayer.setPlayWhenReady(true);
,但它根本没有做任何事情。
我已经将库更新为 ExoPlayer r1.4.2
并且它完成了工作...
mPlayer.seekTo(0);
mPlayer.setPlayWhenReady(true); // replay from start
// 重启后暂停视频
mPlayer.seekTo(0);
mPlayer.setPlayWhenReady(false);
可以使用 LoopingMediaSource 无缝循环播放视频。以下示例无限期地循环 audio/video。也可以在创建 LoopingMediaSource 时指定有限循环次数。
MediaSource source = new ExtractorMediaSource(audioUri, ...);
// Loops the audio indefinitely.
LoopingMediaSource loopingSource = new LoopingMediaSource(source);
或添加一个监听器
playerExo.addListener(new ExoPlayer.Listener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
switch(playbackState) {
case ExoPlayer.STATE_BUFFERING:
break;
case ExoPlayer.STATE_ENDED:
playerExo.seekTo(0);
break;
case ExoPlayer.STATE_IDLE:
break;
case ExoPlayer.STATE_PREPARING:
break;
case ExoPlayer.STATE_READY:
break;
default:
break;
}
}
@Override
public void onPlayWhenReadyCommitted() {
}
@Override
public void onPlayerError(ExoPlaybackException error) {
}
});
playerExo.seekTo(0);
playerExo.setPlayWhenReady(true);//replay from start
/* If you want to Pause audio/video and restart
mPlayer.seekTo(0);
mPlayer.setPlayWhenReady(false);*/
您可以检查 Exoplayer 最新版本是否是最新的:
这段代码对我有用
@OnClick(R.id.image_button_play)
public void play(){
Log.d(TAG, "play: clicked");
//If video has finished then set Exoplayer to 0
if (simpleExoPlayer.getPlaybackState() == Player.STATE_ENDED){
simpleExoPlayer.seekTo(0);
}
simpleExoPlayer.setPlayWhenReady(true);
playButton.setVisibility(View.INVISIBLE);
}
我在 Exoplayer 的基础上使用 DemoPlayer。 我想 restart/replay 视频从某些用户操作 开始 ExoPlayer.STATE_ENDED 已发送。
之后我尝试使用 seekTo(0)
和 mPlayer.setPlayWhenReady(true);
,但它根本没有做任何事情。
我已经将库更新为 ExoPlayer r1.4.2
并且它完成了工作...
mPlayer.seekTo(0);
mPlayer.setPlayWhenReady(true); // replay from start
// 重启后暂停视频
mPlayer.seekTo(0);
mPlayer.setPlayWhenReady(false);
可以使用 LoopingMediaSource 无缝循环播放视频。以下示例无限期地循环 audio/video。也可以在创建 LoopingMediaSource 时指定有限循环次数。
MediaSource source = new ExtractorMediaSource(audioUri, ...);
// Loops the audio indefinitely.
LoopingMediaSource loopingSource = new LoopingMediaSource(source);
或添加一个监听器
playerExo.addListener(new ExoPlayer.Listener() {
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
switch(playbackState) {
case ExoPlayer.STATE_BUFFERING:
break;
case ExoPlayer.STATE_ENDED:
playerExo.seekTo(0);
break;
case ExoPlayer.STATE_IDLE:
break;
case ExoPlayer.STATE_PREPARING:
break;
case ExoPlayer.STATE_READY:
break;
default:
break;
}
}
@Override
public void onPlayWhenReadyCommitted() {
}
@Override
public void onPlayerError(ExoPlaybackException error) {
}
});
playerExo.seekTo(0);
playerExo.setPlayWhenReady(true);//replay from start
/* If you want to Pause audio/video and restart
mPlayer.seekTo(0);
mPlayer.setPlayWhenReady(false);*/
您可以检查 Exoplayer 最新版本是否是最新的:
这段代码对我有用
@OnClick(R.id.image_button_play)
public void play(){
Log.d(TAG, "play: clicked");
//If video has finished then set Exoplayer to 0
if (simpleExoPlayer.getPlaybackState() == Player.STATE_ENDED){
simpleExoPlayer.seekTo(0);
}
simpleExoPlayer.setPlayWhenReady(true);
playButton.setVisibility(View.INVISIBLE);
}