google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

Make UI components DataBinding friendly #5417

Open zishanj opened 5 years ago

zishanj commented 5 years ago

I am trying to use custom player controls and for this purpose I wish to use databinding with my viewmodel. Is it possible to set controller_layout_id of PlayerControlView programmatically so I can attach it with my viewmodel?

ojw28 commented 5 years ago

I don't think this is possible. I'm somewhat unclear exactly how this works though. Is it not possible for you to set it in layout XML?

zishanj commented 5 years ago

with databinding we can use something like this:

MyPlayerBinding myPlayerBinding = DataBindingUtil.inflate(getLayoutInflater(), R.layout.my_player, myActivityBinding.myPlayerControl, false);
myActivityBinding.myPlayerControl.setControllerLayoutId(myPlayerBinding.getRoot());

We only need public access to layout property controller_layout_id so we can set it programmatically. Then we can access viewmodel methods, properties in our layout view. In above example MyPlayerBinding is automatically generated by DataBinding based on our my_player layout filename. myPlayerControl is id for ExoPlayer2.ui.PlayerControlView.

ojw28 commented 5 years ago

I guess what I don't understand, is why do you need to be setting the controller layout programmatically? Why isn't the thing you inflate just the whole player view, which I think would avoid you having this problem? It's also unclear how the need to do this is directly related to databinding. It seems almost orthogonal?

zishanj commented 5 years ago

Without databinding I have to manually use id of views in activity to enable, disable or set listeners etc. or may be have to use another third party lib like ButterKnife. With databinding its very easy to manage the layout from viewmodel based on your specific logic especially when you use MVVM design pattern.

ojw28 commented 5 years ago

Yes, but why can't you inflate a whole player view using DataBindingUtil? That's what I don't understand.

zishanj commented 5 years ago

Entire PlayerControlView still does not give you access to its child layout which is set using controller_layout_id in xml. Using databinding I can only access the parent PlayerControlView not its child controller layout. For this purpose I have to set databinding separately for its child controller.

ojw28 commented 5 years ago

Oh right, the problem is that the controller layout is inflated internally in PlayerControlView, and so isn't inflated by DataBindingUtil.inflate. Is that correct?

zishanj commented 5 years ago

yes... we can't use viewmodel inside child layout and have to inflate it separately.

ojw28 commented 5 years ago

Got it. I don't think that's possible currently, I'm afraid. I'll mark this as an enhancement, but it will be considered low priority since we haven't seen anyone else asking for it.

hafiz013 commented 5 years ago

I think this good question and make high priority since google has move forward to use data binding. Currently, adroid studio also already upgrade which are use data binding as well.

janbolat commented 5 years ago

It would be very helpful to set it programmatically and show different controls depending on some conditions.

musooff commented 5 years ago

I would also vote for High Priority as it is really basic feature that should be included.

arpanbag001 commented 4 years ago

Voting for High Priority, as it is required for use cases where we need to programmatically create PlayerView based on some conditions, and need to attach different controllers on them.

zishanj commented 4 years ago

@ojw28 Any update on this issue? its 2020 now. :)

BlaineOmega commented 4 years ago

I also would like to see this. Most Android apps are going to MVVM and if we want to use data binding along with custom UI controls, this is almost required.

thealteria commented 4 years ago

any leads guys?

HE-LU commented 4 years ago

Must have in 2020. We need this ASAP!

sc941737 commented 3 years ago

So now that Kotlin Synthetics are getting deprecated (:c) and will no longer be in use past September 2021, we really need this ASAP!

yeyintkoko1788 commented 3 years ago

Any update on this issues??

AlexDundar commented 3 years ago

Still no way to use databinding with exoplayer controls??

ashirmehmood1996 commented 3 years ago

we should have an option to set the custom controller programmatically by now. Its 2021 already

schnaps1981 commented 3 years ago

it looks like Google has forgotten about us :(

electrodragon commented 3 years ago

Here is how I'm using with viewBinding.

  1. Add an ID to the root tag of custom controls
<androidx.constraintlayout.widget.ConstraintLayout 
    android:id="@+id/dragon_exo_control_layout"
    xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    >

    <TextView
        android:id="@+id/hello"
        ... 
        />

</androidx.constraintlayout.widget.ConstraintLayout>

Next In your activity onCreate()

YourBindingControlClass exoControlBinding = YourBindingControlClass.bind(findViewByID(R.id.dragon_exo_control_layout));

// Then use it like
exoControlBinding.setText("Hello, World !");
schnaps1981 commented 3 years ago

any news?

mikewalkerjr commented 3 years ago

Please fix this. It should be high priority

victorraft commented 2 years ago

Come on, guys, please fix this :(

SurajBahadur commented 2 years ago

It's been 2022 and by the end of the year, the synthetic binding will vanish from an android ecosystem. Please fix this asap.

theBlbDan commented 1 year ago

View binding please. Another five months gone.

krupa-p-simformsolutions commented 1 year ago

Any update on data binding for custom UI?

schnaps1981 commented 1 year ago

in kotlin 1.8 synthetics will be deleted

Pitel commented 1 year ago

It's 2023, Kotlin 1.8 is here, and I got to this issue hoping to find some solution/workaround. 😿

branostupak commented 1 year ago

We're past mid-2023 and it's still an issue - 3 years highly requested issue.

TonyLead commented 2 months ago

up

herisulistiyanto commented 2 months ago

Any update relate to this issue? Facing this issue as well, need to update kotlin (which synthetic is not supported anymore) then led to this issue