2017-03-08 114 views
2

我正在使用ConcatenatingMediaSource無縫地播放許多MediaSource,這非常有趣,但我無法找到一種方法在玩家開始播放下一個MediaSource時收到回調。ExoPlayer ConcatenatingMediaSource更改源回調

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!? 
} 

回答

2

顯然是正確的回調是onPositionDiscontinuity()和方法來獲得當前MediaSource正在播放的索引ExoPlayer.getCurrentWindowIndex()

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

我想你應該叫player.getCurrentWindowIndex()在onTracksChanged(),這會給你這首歌的索引開始。至少,這將有助於第一首歌。 – akki

+0

我在那裏嘗試過,但它返回錯誤的索引,這工作,也讀[這裏](https://github.com/google/ExoPlayer/issues/2053) – lelloman