在播放ConcatenatingMediaSource
播放列表中的视频时,我希望播放器在新项目开始时自动暂停,例如。不会自动播放。
使用演示应用程序,我修改onPositionDiscontinuity
了函数来检测当前项目的变化:
int currentPosition = 0;
@Override
public void onPositionDiscontinuity(@Player.DiscontinuityReason int reason) {
if (inErrorState) {
// This will only occur if the user has performed a seek whilst in the error state. Update
// the resume position so that if the user then retries, playback will resume from the
// position to which they seeked.
updateResumePosition();
}
if (player.getCurrentWindowIndex() != currentPosition) {
currentPosition = player.getCurrentWindowIndex();
player.setPlayWhenReady(false);
}
}
虽然这段代码暂停了播放器,但它并没有清除播放器使用的表面视图,因此我们仍然看到上一个视频的最后一帧。我想这个回调被调用得太快了,但这是我发现的唯一一个总是在播放列表项更改时调用的回调(onPlayerStateChanged
可能不会被调用)。
如何显示新当前项目的第一帧而不是上一个项目的最后一帧?
我的弱解决方法是延迟 200 毫秒的调用Handler().postDelayed({ mPlayer?.playWhenReady = false }, 200)
。