问题
I have basic code for playing couple of audio files via exoplayer
ExtractorMediaSource audioSource = new ExtractorMediaSource(uri, dataSourceFactory, extractor, null, null);
ExtractorMediaSource audioSource2 = new ExtractorMediaSource(uri2, dataSourceFactory2, extractor, null, null);
ConcatenatingMediaSource concatenatedSource =
new ConcatenatingMediaSource(audioSource, audioSource2);
I'm trying to get duration off all media sources using code example from https://github.com/google/ExoPlayer/issues/2122
Timeline timeline = mMediaPlayer.getCurrentTimeline();
int currentWindowIndex = mMediaPlayer.getCurrentWindowIndex();
long currentPosition = mMediaPlayer.getCurrentPosition();
long totalTime = 0;
Timeline.Window tmpWindow = new Timeline.Window();
if (timeline != null) {
for (int i = 0; i < timeline.getWindowCount(); i++) {
long windowDuration = timeline.getWindow(i,tmpWindow).getDurationMs();
totalTime += windowDuration;
if (i < currentWindowIndex) {
currentPosition += windowDuration;
}
}
}
The problem is that window for the second source returns negative value, and does that until is played for the first time. So I'm guessing that I need to prepare it somehow at the start, but I'm not sure how. There is prepareSource method on MediaSource type of objects, but I'm failing to use it properly.
Did anyone had and success with implementation of this functionality?
来源:https://stackoverflow.com/questions/42798406/exoplayer2-concatenatingmediasource-duration-of-all-sources