4

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?

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?

musooff
  • 6,412
  • 3
  • 36
  • 65

2 Answers2

-1

Use Like this >>>>>

private val binding by lazy {
     ActivityPipVideoPlayerBinding.inflate(layoutInflater)}

private val exoPLayerBinding by lazy {
    VdoExoControlViewBinding.inflate(LayoutInflater.from(this), binding.root, true)
}
-2

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
Abraham Mathew
  • 2,029
  • 3
  • 21
  • 42
  • I suppose you are referring to use Databinding with PlayerView inside you `activity_player.xml`, but my intention is to use Databinding with Custom control view which can be done by creating new layout file `exo_player_control_view.xml`. As in Databinding with custom buttons of `exo_player_control_view` – musooff Feb 18 '19 at 06:30
  • yeah you can hide the default controls and add a custom control view if needed – Abraham Mathew Feb 18 '19 at 06:51
  • Yeah so my question was how to control that `exo_player_control_view` items with Databinding? – musooff Feb 18 '19 at 06:55
  • please go through this post https://stackoverflow.com/a/41631901/8601451 – Abraham Mathew Feb 18 '19 at 07:00
  • Well, as I said I am not asking who to set custom controls, but use those custom controls with Databinding. I guess you didn't get my question. It is in fact an open issue here, So asked in StackOverflow if somehow has work around anyhow. – musooff Feb 18 '19 at 08:14