Xplosive
Xplosive

Reputation: 681

Android - Exoplayer : How to set different controller layout for portrait mode and fullscreen mode?

I am trying to achieve this design with Exo-Player2. Progressbar and some other views position is different in portrait mode and fullscreen mode.

portrait mode landcape mode

As per my research we can pass only one layout design through player view by this line of code: app:controller_layout_id="@layout/bplayer_controller_view"

        <com.google.android.exoplayer2.ui.PlayerView
            android:id="@+id/playerView"
            android:layout_width="match_parent"
            android:layout_height="250dp"
            android:layout_gravity="top"
            android:background="@color/black"
            android:foregroundGravity="center"
            app:controller_layout_id="@layout/bplayer_controller_view"
            app:resize_mode="fill" />

I can't find any way to change this layout in runtime. Did I miss anything? Can you please help me on this topic. Thanks in advance.

Upvotes: 0

Views: 2936

Answers (2)

Nikos M
Nikos M

Reputation: 194

Please follow the steps below:

Res folder -> Right Click -> New -> Android Resource Directory.

Choose layout as Resource Type at the popup that will be displayed(second dropdown).

Then, at the left side choose orientation press >> and OK. A layout_port folder will be created.

Finally, create a layout with the same name as in the main folder(bplayer_controller_view).

Android chooses the correct file depending on requested orientation at runtime!

Upvotes: 0

che10
che10

Reputation: 2318

You cannot change the app:controller_layout_id programmatically. You can also see the same mentioned here. There is no such method at this moment which allows you to directly set a custom controller on playerView and for now you have to add your controller to playerview in xml from where it gets inflated.

Now coming to your problem of having a different custom controller for Landscape and Potrait orientation. There is no direct way of it. Here are some work around options:

  • Have two different ExoPlayer in your XML for orientation and potrait and hide/show them accordingly as per orientation change.
  • The other option will be to have a single FrameLayout in which you can then inflate two different types of ExoPlayer XML Layouts according to the orientation change.

Upvotes: 1

Related Questions