Support for controls in android exoplayer
This commit is contained in:
parent
35e26427ea
commit
4cc9a4d374
@ -64,6 +64,8 @@ import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||
import com.google.android.exoplayer2.upstream.DefaultBandwidthMeter;
|
||||
import com.google.android.exoplayer2.util.MimeTypes;
|
||||
import com.google.android.exoplayer2.util.Util;
|
||||
//Import PlayerControlView
|
||||
import com.google.android.exoplayer2.ui.PlayerControlView;
|
||||
|
||||
import java.net.CookieHandler;
|
||||
import java.net.CookieManager;
|
||||
@ -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;
|
||||
@ -257,6 +261,41 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
|
||||
// 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() {
|
||||
if (player == null) {
|
||||
TrackSelection.Factory videoTrackSelectionFactory = new AdaptiveTrackSelection.Factory(BANDWIDTH_METER);
|
||||
@ -517,6 +556,10 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
onBuffering(false);
|
||||
startProgressHandler();
|
||||
videoLoaded();
|
||||
//Setting the visibility for the playerControlView
|
||||
if(playerControlView != null) {
|
||||
playerControlView.setVisibility(VISIBLE);
|
||||
}
|
||||
break;
|
||||
case ExoPlayer.STATE_ENDED:
|
||||
text += "ended";
|
||||
@ -1056,4 +1099,16 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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() {
|
||||
@ -255,6 +256,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
|
||||
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;
|
||||
|
Loading…
Reference in New Issue
Block a user