如何用数据绑定实现ExoPlayer

如何用数据绑定实现ExoPlayer

本文介绍了如何用数据绑定实现ExoPlayer?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个类activity_player布局,在其中我具有exoplayer2.ui.PlayerView并创建了exo_player_control_view,以便它覆盖ExoPlayer中的默认控件.因此,我想在新创建的自定义控件视图中使用数据绑定,但不知道该怎么做.有什么建议吗?

I have a class activity_player layout in which I have exoplayer2.ui.PlayerView and I created exo_player_control_view so that it overrides default controls in ExoPlayer. So I wanted to use Databinding in newly created custom control view but don't know how to do it. Any advice?

这实际上是在此处的未解决问题,但尚未解决.那么,有没有人有变通办法以使exo_player_control_view数据绑定友好?

It is actually an open issue over here, but yet to be solved. So is there anyone who had a workaround to make exo_player_control_view Databinding friendly?

推荐答案

您可以在片段/活动中使用绑定变量来访问片段/活动中的playerView和

You can use binding variable inside fragment/activity to access the playerView inside fragment/activity and

  val uri: Uri? = if (url is String) Uri.parse(url as String?) else url as Uri?
    val trackSelector =
        DefaultTrackSelector(AdaptiveTrackSelection.Factory(DefaultBandwidthMeter()))
    val player: SimpleExoPlayer = ExoPlayerFactory.newSimpleInstance(view.context, trackSelector)
    val dataSourceFactory = DefaultDataSourceFactory(view.context, "ua")
    val mediaSource =
        ExtractorMediaSource(uri, dataSourceFactory, DefaultExtractorsFactory(), null, null)
    player.prepare(mediaSource)
    player.apply {
        volume = 0f
        repeatMode = Player.REPEAT_MODE_ONE
        playWhenReady = true
        videoScalingMode = C.VIDEO_SCALING_MODE_SCALE_TO_FIT
    }
    binding.playerView.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL)
    binding.playerView.player = player

这篇关于如何用数据绑定实现ExoPlayer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 04:03