2017-03-07 86 views
1

我使用ExoPlayer 2播放遠程音軌。默認情況下,玩家一次一個地加載音軌(即大約20秒,然後在軌道播放時再加20秒)。ExoPlayer,如何加載遠程音頻文件的大部分

由於曲目是從遠程服務器加載的,所以發生如果連接斷開,播放器無法再加載。有沒有辦法說ExoPlayer加載音頻文件的更大部分(同時也是完整的曲目)?

我試圖看到ExtractorMediaSource,DataSource.FactoryDefaultExtractorsFactory左右,但我找不到解決我的問題。

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

mExoPlayer.prepare(audioSource) 
mExoPlayer.playWhenReady = true 

(這是科特林,但它似乎也可以理解由Java程序員)

回答

6

我已經找到了解決辦法。因爲我沒有找到其他相關的問題,我會回答我的問題(希望有人會需要它在未來):

配置正確的對象是創建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() 
) 
mExoPlayer = ExoPlayerFactory.newSimpleInstance(this, trackSelector, loadControl) 

The doc它在那裏解釋。

+0

非常有幫助。謝謝。 – akki