ExoPlayer仅在HLS流上使用最低再现

时间:2018-10-31 23:14:21

标签: exoplayer exoplayer2.x

我似乎对ExoPlayer有问题,不想使用任何更高版本的版本。流具有8个再现,但是ExoPlayer仅使用AdaptiveTrackSelection选择最低的再现。当我手动将其设置为1080p格式(使用ExoPlayer-UI中的TrackSelectionView对话框)时,它运行良好。

这是播放器的代码。我跟随了演示。该流在演示应用程序中工作正常。

open class VideoPlayer(val context: Context, val videoTitle: String) {
   val bandwidthMeter = DefaultBandwidthMeter()
   val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeter)
   var trackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
   var player: SimpleExoPlayer

   init {
       player = ExoPlayerFactory.newSimpleInstance(context, trackSelector)
   }

   fun setUrl(url: String, playWhenReady: Boolean = true) {
       player.playWhenReady = playWhenReady
       val mediaDataSourceFactory = DefaultDataSourceFactory(context, Util.getUserAgent(context, "Player"))
       val mediaSource = HlsMediaSource.Factory(mediaDataSourceFactory).createMediaSource(Uri.parse(url))
       player.prepare(mediaSource)
   }

   fun releasePlayer() {
       player.release()
   }
}

感谢您的帮助!谢谢!

1 个答案:

答案 0 :(得分:0)

一个愚蠢的错误。忘记在DefaultDataSourceFactory中传递bandwithMeter!