ExoPlayer
ExoPlayer copied to clipboard
Make UI components DataBinding friendly
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?
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?
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.
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?
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.
Yes, but why can't you inflate a whole player view using DataBindingUtil? That's what I don't understand.
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.
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?
yes... we can't use viewmodel inside child layout and have to inflate it separately.
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.
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.
It would be very helpful to set it programmatically and show different controls depending on some conditions.
I would also vote for High Priority as it is really basic feature that should be included.
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.
@ojw28 Any update on this issue? its 2020 now. :)
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.
any leads guys?
Must have in 2020. We need this ASAP!
So now that Kotlin Synthetics are getting deprecated (:c) and will no longer be in use past September 2021, we really need this ASAP!
Any update on this issues??
Still no way to use databinding with exoplayer controls??
we should have an option to set the custom controller programmatically by now. Its 2021 already
it looks like Google has forgotten about us :(
Here is how I'm using with viewBinding.
- 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 !");
any news?
Please fix this. It should be high priority
Come on, guys, please fix this :(
It's been 2022 and by the end of the year, the synthetic binding will vanish from an android ecosystem. Please fix this asap.
View binding please. Another five months gone.
Any update on data binding for custom UI?
in kotlin 1.8 synthetics will be deleted