android - ExoPlayer ConcatenatingMediaSource 改源回调

标签 android exoplayer

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

ExoPlayer.EventLister.onTracksChanged(TrackGroupArray, TrackSelected)MediaSource 更改时被调用(此时我可以听到新轨道),所以看起来正确的位置,但如何检索正在播放的 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();
}    

关于android - ExoPlayer ConcatenatingMediaSource 改源回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42674757/

相关文章:

java - Android 获取 XML 值

android - 实现 Drm Dash 媒体源时发生 DecoderInitializationException

java - 如何在 exo 播放器中获取当前视频时长?

android - 如何修复此 PlayerNotificationManager.createWithNotificationChannel 错误

android - 意向服务及其优势

Android:通过滑动而不是通过按钮保存表单数据

android - Sqlite数据库中,如何在表中同时插入多行

java - 变量变为 Null

android - ExoPlayer - 在整个音频剪辑播放过程中显示 PlayerControlView

android - 使用 ExoPlayer v2 的互联网广播流