Mar*_*vić 5 android duration exoplayer exoplayer2.x
我有通过 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);
Run Code Online (Sandbox Code Playgroud)
我正在尝试使用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;
}
}
}
Run Code Online (Sandbox Code Playgroud)
问题是第二个源的窗口返回负值,并且直到第一次播放为止。所以我猜我需要在一开始就以某种方式做好准备,但我不确定如何做。MediaSource 类型的对象有prepareSource 方法,但我无法正确使用它。
有人成功实现了此功能吗?
| 归档时间: |
|
| 查看次数: |
1401 次 |
| 最近记录: |