【问题标题】:seekTo(mTimeMilis) won't work properly when using ConcatenatingMediaSource in ExoPlayer在 ExoPlayer 中使用 ConcatenatingMediaSource 时 seekTo(mTimeMilis) 无法正常工作
【发布时间】:2019-05-09 21:39:19
【问题描述】:

我有多个视频要一一播放。创建每个视频的 MediaSource 后,所有这些都将发送到 ConcatenatingMediaSource(mediaSources[])。一般是一一播放。但是当视频使用seekTo()快进时,第一个视频可以,但其他视频不跟随seekTo()

假设第一个视频是 10 秒,第二个 12 秒,第三个 10 秒。 如果我打电话给seekTo((long)12*1000),它应该以 2 秒的速度播放第二个视频。但它从第二个视频的开头播放。

设置视频源

DefaultDataSourceFactory defaultDataSourceFactory = new DefaultDataSourceFactory(getApplicationContext(),Util.getUserAgent(getApplicationContext(), "ExoPlayer"));
MediaSource mediaSource = new ExtractorMediaSource.Factory(defaultDataSourceFactory).createMediaSource(videoItem.getVideoUri());
videoItemArrayList.get(k).setVideoSource(mediaSource);

连接源

MediaSource[] mediaSources = new MediaSource[videoItemArrayList.size()];
int j=0;
for(VideoItem item : videoItemArrayList){
    mediaSources[j] = item.getVideoSource();
    ++j;
}
concatenatedSource = new ConcatenatingMediaSource(mediaSources);

设置外层播放器

exoPlayer.prepare(concatenatedSource);
exoPlayer.seekTo(0);
exoPlayer.setPlayWhenReady(true);
exoPlayer.getPlaybackState();

【问题讨论】:

    标签: android exoplayer2.x


    【解决方案1】:

    在源内部使用exoplayer.seekTo(period) 在内部调用currentWindowIndex()。当您在连接的媒体源中播放第一个视频时,您最终会收到 windowIndex 为 0。使用 seekTo(windowIndex, time) 解决问题。

    【讨论】:

    • 是否始终保证连接媒体源中的每个媒体源都有一个窗口?所以当我调用 seekTo(2, 3000) 时,这将始终播放列表中的媒体源编号 2?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-23
    • 1970-01-01
    • 2018-10-29
    • 2013-03-03
    • 2020-07-13
    相关资源
    最近更新 更多