目前,我遇到了新版 Exoplayer 的问题。以下是播放器启动时使用的代码。在getPlayerStart()中,我传递了url链接。在initExoPlayer()中,我正在初始化我的 Exoplayer 但在早期版本的 Exoplayer 中我遇到了这个问题:
以上功能显示不可用
private fun getPlayerStart(urlLink: String) {
if (playerMode) {
val userAgent = Util.getUserAgent(context, context!!.getApplicationInfo().packageName)
val httpDataSourceFactory = DefaultHttpDataSourceFactory(userAgent, null, DefaultHttpDataSource.DEFAULT_CONNECT_TIMEOUT_MILLIS, DefaultHttpDataSource.DEFAULT_READ_TIMEOUT_MILLIS, true)
val dataSourceFactory = DefaultDataSourceFactory(context, null, httpDataSourceFactory)
Log.i("Video",urlLink)
val daUri = Uri.parse(urlLink)
val extractorsFactory = DefaultExtractorsFactory()
mVideoSource = ExtractorMediaSource(daUri, dataSourceFactory,
extractorsFactory, null, null) as MediaSource?
}
initExoPlayer()
}
private fun initExoPlayer() {
val bandwidthMeter = DefaultBandwidthMeter()
val videoTrackSelectionFactory = AdaptiveTrackSelection.Factory(bandwidthMeter)
val trackSelector = DefaultTrackSelector(videoTrackSelectionFactory)
val loadControl = DefaultLoadControl()
player = ExoPlayerFactory.newSimpleInstance(DefaultRenderersFactory(context), trackSelector, loadControl)
mExoPlayerView!!.player= this.player
player!!.addListener(this)
mExoPlayerView!!.player.prepare(mVideoSource)
mExoPlayerView!!.getPlayer().playWhenReady = true
}
答案 0 :(得分:0)
prepare()
方法是ExoPlayer
接口的一部分,该接口扩展了Player
接口。
PlayerView
仅公开没有准备方法的Player
接口。这就是为什么你不能mExoPlayerView!!.player.prepare(mVideoSource)
。
但是,您使用的ExoPlayerFactory
确实会返回一个实现了SimpleExoPlayer
接口的ExoPlayer
实例:
SimpleExoPlayer player = ExoPlayerFactory.newSimpleInstance(new DefaultRenderersFactory(context), trackSelector, loadControl);
player.prepare(mediaSource);
以下是ExoPlayer
和Player
接口以及SimpleExoPlayer
的类引用:
https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/Player.html https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/ExoPlayer.html https://exoplayer.dev/doc/reference/com/google/android/exoplayer2/SimpleExoPlayer.html