Support for controls in android exoplayer

This commit is contained in:
Ibrahim Sulaiman 2019-01-04 14:58:32 +05:30
parent 35e26427ea
commit 4cc9a4d374
2 changed files with 61 additions and 0 deletions

View File

@ -64,6 +64,8 @@ import com.google.android.exoplayer2.upstream.BandwidthMeter;
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter; import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.util.MimeTypes; import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util; import com.google.android.exoplayer2.util.Util;
//Import PlayerControlView
import com.google.android.exoplayer2.ui.PlayerControlView;
import java.net.CookieHandler; import java.net.CookieHandler;
import java.net.CookieManager; import java.net.CookieManager;
@ -96,6 +98,8 @@ class ReactExoplayerView extends FrameLayout implements
} }
private final VideoEventEmitter eventEmitter; private final VideoEventEmitter eventEmitter;
//Create playerControlView instance
private PlayerControlView playerControlView;
private Handler mainHandler; private Handler mainHandler;
private ExoPlayerView exoPlayerView; private ExoPlayerView exoPlayerView;
@ -257,6 +261,41 @@ class ReactExoplayerView extends FrameLayout implements
} }
// Internal methods // Internal methods
/**
* Toggling the visibility of the player control view
*/
private void togglePlayerControlVisibility() {
if(playerControlView.isVisible()) {
playerControlView.setVisibility(INVISIBLE);
} else {
playerControlView.setVisibility(VISIBLE);
}
}
/**
* Initialising Player control
*/
private void initialisePlayerControl() {
playerControlView = new PlayerControlView(getContext());
LayoutParams layoutParams = new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
playerControlView.setLayoutParams(layoutParams);
addView(playerControlView, 1, layoutParams);
//Setting the player for the playerControlView
playerControlView.setPlayer(player);
//Invoking onClick event for exoplayerView
exoPlayerView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
togglePlayerControlVisibility();
}
});
}
private void initializePlayer() { private void initializePlayer() {
if (player == null) { if (player == null) {
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER); TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
@ -517,6 +556,10 @@ class ReactExoplayerView extends FrameLayout implements
onBuffering(false); onBuffering(false);
startProgressHandler(); startProgressHandler();
videoLoaded(); videoLoaded();
//Setting the visibility for the playerControlView
if(playerControlView != null) {
playerControlView.setVisibility(VISIBLE);
}
break; break;
case ExoPlayer.STATE_ENDED: case ExoPlayer.STATE_ENDED:
text += "ended"; text += "ended";
@ -1056,4 +1099,16 @@ class ReactExoplayerView extends FrameLayout implements
releasePlayer(); releasePlayer();
initializePlayer(); initializePlayer();
} }
/**
* Handling controls prop
*
* @param controls value of the controls prop passed from react-native
*/
public void setControls(boolean controls) {
if(controls && (exoPlayerView != null)) {
//Initialise playerControlView
initialisePlayerControl();
}
}
} }

View File

@ -57,6 +57,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
private static final String PROP_SELECTED_VIDEO_TRACK_TYPE = "type"; private static final String PROP_SELECTED_VIDEO_TRACK_TYPE = "type";
private static final String PROP_SELECTED_VIDEO_TRACK_VALUE = "value"; private static final String PROP_SELECTED_VIDEO_TRACK_VALUE = "value";
private static final String PROP_HIDE_SHUTTER_VIEW = "hideShutterView"; private static final String PROP_HIDE_SHUTTER_VIEW = "hideShutterView";
private static final String PROP_CONTROLS = "controls";
@Override @Override
public String getName() { public String getName() {
@ -255,6 +256,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
videoView.setHideShutterView(hideShutterView); videoView.setHideShutterView(hideShutterView);
} }
@ReactProp(name = PROP_CONTROLS, defaultBoolean = false)
public void setControls(final ReactExoplayerView videoView, final boolean controls) {
videoView.setControls(controls);
}
@ReactProp(name = PROP_BUFFER_CONFIG) @ReactProp(name = PROP_BUFFER_CONFIG)
public void setBufferConfig(final ReactExoplayerView videoView, @Nullable ReadableMap bufferConfig) { public void setBufferConfig(final ReactExoplayerView videoView, @Nullable ReadableMap bufferConfig) {
int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS; int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;