Resolved the playercontrol UI issue and also handled the controls prop state

This commit is contained in:
Ibrahim Sulaiman 2019-01-25 15:54:53 +05:30
parent e05c1c3c64
commit debc0cb3c6
2 changed files with 84 additions and 2 deletions

View File

@ -275,7 +275,9 @@ class ReactExoplayerView extends FrameLayout implements
* Initializing Player control
*/
private void initializePlayerControl() {
playerControlView = new PlayerControlView(getContext());
if(playerControlView == null) {
playerControlView = new PlayerControlView(getContext());
}
LayoutParams layoutParams = new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
@ -284,6 +286,7 @@ class ReactExoplayerView extends FrameLayout implements
//Setting the player for the playerControlView
playerControlView.setPlayer(player);
playerControlView.setVisibility(VISIBLE);
//Invoking onClick event for exoplayerView
exoPlayerView.setOnClickListener(new OnClickListener() {
@ -1104,9 +1107,13 @@ class ReactExoplayerView extends FrameLayout implements
* @param controls value of the controls prop passed from react-native
*/
public void setControls(boolean controls) {
if(controls && (exoPlayerView != null)) {
if(controls && (exoPlayerView != null)) {
//Initialize playerControlView
initializePlayerControl();
} else {
if(getChildAt(1) instanceof PlayerControlView && (exoPlayerView != null)){
removeViewAt(1);
}
}
}
}

View File

@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layoutDirection="ltr"
android:background="#CC000000"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingTop="4dp"
android:orientation="horizontal">
<ImageButton android:id="@id/exo_prev"
style="@style/ExoMediaButton.Previous"/>
<ImageButton android:id="@id/exo_rew"
style="@style/ExoMediaButton.Rewind"/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<ImageButton android:id="@id/exo_play"
style="@style/ExoMediaButton.Play"/>
<ImageButton android:id="@id/exo_pause"
style="@style/ExoMediaButton.Pause"/>
</FrameLayout>
<ImageButton android:id="@id/exo_ffwd"
style="@style/ExoMediaButton.FastForward"/>
<ImageButton android:id="@id/exo_next"
style="@style/ExoMediaButton.Next"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView android:id="@id/exo_position"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:includeFontPadding="false"
android:textColor="#FFBEBEBE"/>
<com.google.android.exoplayer2.ui.DefaultTimeBar
android:id="@id/exo_progress"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="26dp"/>
<TextView android:id="@id/exo_duration"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:textSize="14sp"
android:textStyle="bold"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:includeFontPadding="false"
android:textColor="#FFBEBEBE"/>
</LinearLayout>
</LinearLayout>