add fullscreenOrientation

This commit is contained in:
Tuan Luong 2020-07-10 10:45:41 +07:00
parent 0b7ea71d77
commit 5fe76574bb
4 changed files with 35 additions and 17 deletions

View File

@ -469,7 +469,7 @@ Platforms: iOS
* **landscape**
* **portrait**
Platforms: iOS
Platforms: Android ExoPlayer, iOS
#### headers
Pass headers to the HTTP client. Can be used for authorization. Headers must be a part of the source object.

View File

@ -1,5 +1,6 @@
package com.brentvatne.exoplayer;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
@ -14,7 +15,8 @@ import com.google.android.exoplayer2.ui.PlayerControlView;
public class ExoPlayerFullscreenVideoActivity extends AppCompatActivity implements ReactExoplayerView.FullScreenDelegate {
public static final String EXTRA_ID = "extra_id";
public static final String EXTRA_ORIENTATION = "extra_orientation";
private int id;
private PlayerControlView playerControlView;
private SimpleExoPlayer player;
@ -22,8 +24,14 @@ public class ExoPlayerFullscreenVideoActivity extends AppCompatActivity implemen
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.exo_player_fullscreen_video);
id = getIntent().getIntExtra(EXTRA_ID, -1);
String orientation = getIntent().getStringExtra(EXTRA_ORIENTATION);
if ("landscape".equals(orientation)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
} else if ("portrait".equals(orientation)) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
}
setContentView(R.layout.exo_player_fullscreen_video);
player = ReactExoplayerView.getViewInstance(id).getPlayer();
ExoPlayerView playerView = findViewById(R.id.player_view);
@ -54,20 +62,18 @@ public class ExoPlayerFullscreenVideoActivity extends AppCompatActivity implemen
super.onResume();
boolean isPaused = ReactExoplayerView.getViewInstance(id).isPaused();
player.setPlayWhenReady(!isPaused);
ReactExoplayerView.getViewInstance(id).registerFullScreenDelegate(this);
if (ReactExoplayerView.getViewInstance(id) != null) {
ReactExoplayerView.getViewInstance(id).registerFullScreenDelegate(this);
}
}
@Override
public void onPause() {
super.onPause();
player.setPlayWhenReady(false);
ReactExoplayerView.getViewInstance(id).registerFullScreenDelegate(null);
}
@Override
protected void onDestroy() {
super.onDestroy();
ReactExoplayerView.getViewInstance(id).removeViewInstance();
if (ReactExoplayerView.getViewInstance(id) != null) {
ReactExoplayerView.getViewInstance(id).registerFullScreenDelegate(null);
}
}
@Override
@ -81,8 +87,11 @@ public class ExoPlayerFullscreenVideoActivity extends AppCompatActivity implemen
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
ReactExoplayerView.getViewInstance(id).setFullscreen(false);
return false;
if (ReactExoplayerView.getViewInstance(id) != null) {
ReactExoplayerView.getViewInstance(id).setFullscreen(false);
return false;
}
return true;
}
return super.onKeyDown(keyCode, event);
}

View File

@ -114,6 +114,7 @@ class ReactExoplayerView extends FrameLayout implements
private long resumePosition;
private boolean loadVideoStarted;
private boolean isFullscreen;
private String fullScreenOrientation;
private boolean isInBackground;
private boolean isPaused;
private boolean isBuffering;
@ -266,6 +267,7 @@ class ReactExoplayerView extends FrameLayout implements
public void cleanUpResources() {
stopPlayback();
instances.remove(uid);
}
//BandwidthMeter.EventListener implementation
@ -300,10 +302,6 @@ class ReactExoplayerView extends FrameLayout implements
this.fullScreenDelegate = delegate;
}
public void removeViewInstance() {
instances.remove(uid);
}
// Internal methods
/**
@ -323,6 +321,7 @@ class ReactExoplayerView extends FrameLayout implements
instances.put(uid, this);
Intent intent = new Intent(getContext(), ExoPlayerFullscreenVideoActivity.class);
intent.putExtra(ExoPlayerFullscreenVideoActivity.EXTRA_ID, this.uid);
intent.putExtra(ExoPlayerFullscreenVideoActivity.EXTRA_ORIENTATION, this.fullScreenOrientation);
getContext().startActivity(intent);
}
@ -1268,6 +1267,10 @@ class ReactExoplayerView extends FrameLayout implements
}
}
public void setFullscreenOrientation(String orientation) {
this.fullScreenOrientation = orientation;
}
public void setUseTextureView(boolean useTextureView) {
exoPlayerView.setUseTextureView(useTextureView);
}

View File

@ -54,6 +54,7 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
private static final String PROP_PLAY_IN_BACKGROUND = "playInBackground";
private static final String PROP_DISABLE_FOCUS = "disableFocus";
private static final String PROP_FULLSCREEN = "fullscreen";
private static final String PROP_FULLSCREEN_ORIENTATION = "fullscreenOrientation";
private static final String PROP_USE_TEXTURE_VIEW = "useTextureView";
private static final String PROP_SELECTED_VIDEO_TRACK = "selectedVideoTrack";
private static final String PROP_SELECTED_VIDEO_TRACK_TYPE = "type";
@ -264,6 +265,11 @@ public class ReactExoplayerViewManager extends ViewGroupManager<ReactExoplayerVi
videoView.setFullscreen(fullscreen);
}
@ReactProp(name = PROP_FULLSCREEN_ORIENTATION)
public void setFullscreenOrientation(final ReactExoplayerView videoView, final String fullscreenOrientation) {
videoView.setFullscreenOrientation(fullscreenOrientation);
}
@ReactProp(name = PROP_USE_TEXTURE_VIEW, defaultBoolean = true)
public void setUseTextureView(final ReactExoplayerView videoView, final boolean useTextureView) {
videoView.setUseTextureView(useTextureView);