簡體   English   中英

ExoPlayer,如何加載遠程音頻文件的更大部分

[英]ExoPlayer, how to load bigger parts of remote audio files

我正在使用 ExoPlayer 2 播放遠程曲目。 默認情況下,播放器逐個加載曲目(即大約 20 秒,然后在曲目播放時加載其他 20 秒)。

由於曲目是從遠程服務器加載的,因此如果連接中斷,播放器將無法再加載。 有沒有辦法讓 ExoPlayer 加載音頻文件的更大部分(也是一次完整的軌道)?

我試圖查看ExtractorMediaSourceDataSource.FactoryDefaultExtractorsFactory但我找不到任何可以解決我的問題的方法。

val audioSource = ExtractorMediaSource(
        Uri.parse(videoUrl),
        mDataSourceFactory,    // DataSource.Factory
        mExtractor,    // DefaultExtractorsFactory
        null,
        null
)

mExoPlayer.prepare(audioSource)
mExoPlayer.playWhenReady = true

(它是 Kotlin,但 Java 程序員似乎也可以理解)

我找到了解決方案。 由於我沒有找到其他相關問題,我將回答我的問題(我希望將來有人需要它):

要配置的正確對象是在創建ExoPlayer對象時傳遞給ExoPlayerFactoryLoadControl

原始答案(已棄用):

val loadControl = DefaultLoadControl(
            DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE),
            5 * 60 * 1000, // this is it!
            10 * 60 * 1000,
            DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS.toLong(),
            DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS.toLong()
)
exoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl)

更新的答案:

val bandwidthMeter = DefaultBandwidthMeter.Builder(context).build()
val trackSelectionFactory = AdaptiveTrackSelection.Factory()
val trackSelector = DefaultTrackSelector(trackSelectionFactory)

val loadControl = DefaultLoadControl.Builder()
        .setAllocator(DefaultAllocator(true, C.DEFAULT_BUFFER_SEGMENT_SIZE))
        .setBufferDurationsMs(
            5 * 60 * 1000, // this is it!
            10 * 60 * 1000,
            DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS,
            DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS
        )
        .setTargetBufferBytes(DefaultLoadControl.DEFAULT_TARGET_BUFFER_BYTES)
        .setPrioritizeTimeOverSizeThresholds(DefaultLoadControl.DEFAULT_PRIORITIZE_TIME_OVER_SIZE_THRESHOLDS)
        .createDefaultLoadControl()

exoPlayer = ExoPlayerFactory.newSimpleInstance(
        context,
        DefaultRenderersFactory(context),
        trackSelector,
        loadControl,
        null,
        bandwidthMeter)

解釋它的文檔

@Massimo 的答案是正確的,但方法已被棄用

使用這樣的東西

DefaultLoadControl.Builder()
            .setBufferDurationsMs(
                DefaultLoadControl.DEFAULT_MIN_BUFFER_MS, 
                30_000, 
                DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS,
                DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS
            )

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM