其他分享
首页 > 其他分享> > android-ExoPlayer ConcatenatingMediaSource更改源回调

android-ExoPlayer ConcatenatingMediaSource更改源回调

作者:互联网

我正在使用ConcatenatingMediaSource无缝播放许多MediaSource,这很有趣,但是当播放器开始播放下一个MediaSource时,我找不到接收回调的方法.

当MediaSource发生变化时,ExoPlayer.EventLister.onTracksChanged(TrackGroupArray,TrackSelected)被调用(此时我可以听到新的曲目),因此看起来好像是正确的位置,但是如何检索正在播放的MediaSource的索引呢?

MediaSource[] allSources = // ...
ConcatenatingMediaSource source = new ConcatenatingMediaSource(allSources);

ExoPlayer player = // ..
player.prepare(source);

// ...

@Override
public void onTracksChanged(TrackGroupArray trackGroups, TrackSelectionArray trackSelections) {
    // Can I retrieve the index of the MediaSource currently being played here?
    // If not, where!?
}

解决方法:

显然,正确的回调是onPositionDiscontinuity(),获取正在播放的当前MediaSource的索引的方法是ExoPlayer.getCurrentWindowIndex()

@Override
public void onPositionDiscontinuity() {        
    int sourceIndex = player.getCurrentWindowIndex();
}    

标签:exoplayer,android
来源: https://codeday.me/bug/20191026/1934475.html