Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ExoPlayer: Place controller under the video without overlapping the video

Tags:

I have a PlayerView that takes up the top half of the Activity in portrait orientation with the bottom half of the screen showing some text.

I need to have the controller under the video without overlapping the video content (it will always be shown). By default when a user touches the video the controller appears at the bottom of the video covering the bottom part of the video. I my case I need the controller to stick under the video with no intersections with the video content.

I went through SimpleExoPlayer and PlayerView APIs but I haven't found any way to do so.

Question: How can I place the controller under the video with ExoPlayer?

Here is how the layout looks like:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     android:layout_width="match_parent"     android:layout_height="match_parent">      <com.google.android.exoplayer2.ui.PlayerView         android:id="@+id/video_view"         android:layout_width="match_parent"         android:layout_height="wrap_content"/>      <TextView         android:id="@+id/text"         android:layout_width="wrap_content"         android:layout_height="wrap_content"         android:layout_alignParentStart="true"         android:layout_below="@id/video_view"         android:scrollbars="vertical" />  </RelativeLayout> 
like image 566
Sasha Shpota Avatar asked Aug 05 '18 12:08

Sasha Shpota


2 Answers

This will push the controls down to the bottom of the screen:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:app="http://schemas.android.com/apk/res-auto"     android:layout_width="match_parent"     android:layout_height="match_parent">      <com.google.android.exoplayer2.ui.PlayerView         android:id="@+id/video_view"         android:layout_width="match_parent"         android:layout_height="wrap_content"         app:use_controller="false" />      <com.google.android.exoplayer2.ui.PlayerControlView         android:id="@+id/controls"         android:layout_width="match_parent"         android:layout_height="wrap_content"         android:layout_below="@id/video_view"         app:show_timeout="0" />     </RelativeLayout> 

Then in Java:

PlayerView videoView = findViewById(R.id.video_view); PlayerControlView controls = findViewById(R.id.controls); controls.setPlayer(videoView.getPlayer()); 

Edit: Modified my answer to suggestion from @RashimiGautam

like image 86
Pierre Avatar answered Sep 18 '22 12:09

Pierre


Refer to the answer by @Pierre.
Also to remove controller from above PlayerView, in that case, @id/video_view by writing player.showController(false) in java file.
You can also use app:use_controller:false in the xml.
So you will the only the video without controller on top. And link it to a new controller, in that case, @id/controls at the bottom of the video.

like image 22
Rashmi Gautam Avatar answered Sep 19 '22 12:09

Rashmi Gautam