Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for displaying controls in Android Exoplayer #1414

Merged
merged 9 commits into from
Feb 11, 2019
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ Note on iOS, controls are always shown when in fullscreen mode.

Controls are not available Android because the system does not provide a stock set of controls. You will need to build your own or use a package like [react-native-video-controls](https://github.com/itsnubix/react-native-video-controls) or [react-native-video-player](https://github.com/cornedor/react-native-video-player).

Platforms: iOS, react-native-dom
Platforms: iOS, Android, react-native-dom
IbrahimSulai marked this conversation as resolved.
Show resolved Hide resolved

#### filter
Add video filter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
import com.google.android.exoplayer2.util.MimeTypes;
import com.google.android.exoplayer2.util.Util;
//Import PlayerControlView
IbrahimSulai marked this conversation as resolved.
Show resolved Hide resolved
import com.google.android.exoplayer2.ui.PlayerControlView;

import java.net.CookieHandler;
import java.net.CookieManager;
Expand Down Expand Up @@ -96,6 +98,8 @@ class ReactExoplayerView extends FrameLayout implements
}

private final VideoEventEmitter eventEmitter;
//Create playerControlView instance
private PlayerControlView playerControlView;

private Handler mainHandler;
private ExoPlayerView exoPlayerView;
Expand Down Expand Up @@ -257,6 +261,41 @@ public void onBandwidthSample(int elapsedMs, long bytes, long bitrate) {
}

// 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() {
IbrahimSulai marked this conversation as resolved.
Show resolved Hide resolved
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() {
if (player == null) {
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
Expand Down Expand Up @@ -517,6 +556,10 @@ public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
onBuffering(false);
startProgressHandler();
videoLoaded();
//Setting the visibility for the playerControlView
if(playerControlView != null) {
playerControlView.setVisibility(VISIBLE);
}
break;
case ExoPlayer.STATE_ENDED:
text += "ended";
Expand Down Expand Up @@ -1056,4 +1099,16 @@ public void setBufferConfig(int newMinBufferMs, int newMaxBufferMs, int newBuffe
releasePlayer();
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();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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_VALUE = "value";
private static final String PROP_HIDE_SHUTTER_VIEW = "hideShutterView";
private static final String PROP_CONTROLS = "controls";

@Override
public String getName() {
Expand Down Expand Up @@ -255,6 +256,11 @@ public void setHideShutterView(final ReactExoplayerView videoView, final boolean
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)
public void setBufferConfig(final ReactExoplayerView videoView, @Nullable ReadableMap bufferConfig) {
int minBufferMs = DefaultLoadControl.DEFAULT_MIN_BUFFER_MS;
Expand Down