forked from TheWidlarzGroup/react-native-video
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
revert back ExoPlayerFullscreenVideoActivity
original PR: TheWidlarzGroup#2073 Removed ExoPlayerFullscreenVideoActivity PR: TheWidlarzGroup@daf5e59
- Loading branch information
Showing
7 changed files
with
294 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
package="com.brentvatne.react"> | ||
<application> | ||
<activity | ||
android:name="com.brentvatne.exoplayer.ExoPlayerFullscreenVideoActivity" | ||
android:configChanges="orientation|keyboardHidden|screenSize" | ||
android:launchMode="singleTop" /> | ||
</application> | ||
</manifest> |
155 changes: 155 additions & 0 deletions
155
android/src/main/java/com/brentvatne/exoplayer/ExoPlayerFullscreenVideoActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
package com.brentvatne.exoplayer; | ||
|
||
import android.content.pm.ActivityInfo; | ||
import android.os.Bundle; | ||
import android.view.KeyEvent; | ||
import android.view.View; | ||
import android.view.WindowManager; | ||
import android.widget.ImageView; | ||
|
||
import androidx.appcompat.app.AppCompatActivity; | ||
|
||
import com.brentvatne.react.R; | ||
import com.google.android.exoplayer2.Player; | ||
import com.google.android.exoplayer2.ExoPlayer; | ||
import com.google.android.exoplayer2.ui.PlayerControlView; | ||
|
||
public class ExoPlayerFullscreenVideoActivity extends AppCompatActivity implements ReactExoplayerView.FullScreenDelegate { | ||
public static final String EXTRA_EXO_PLAYER_VIEW_ID = "extra_id"; | ||
public static final String EXTRA_ORIENTATION = "extra_orientation"; | ||
|
||
private ReactExoplayerView exoplayerView; | ||
private PlayerControlView playerControlView; | ||
private ExoPlayer player; | ||
|
||
@Override | ||
public void onCreate(Bundle savedInstanceState) { | ||
int exoplayerViewId = getIntent().getIntExtra(EXTRA_EXO_PLAYER_VIEW_ID, -1); | ||
exoplayerView = ReactExoplayerView.getViewInstance(exoplayerViewId); | ||
if (exoplayerView == null) { | ||
finish(); | ||
return; | ||
} | ||
super.onCreate(savedInstanceState); | ||
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); | ||
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 = exoplayerView.getPlayer(); | ||
|
||
ExoPlayerView playerView = findViewById(R.id.player_view); | ||
playerView.setPlayer(player); | ||
playerView.setOnClickListener(v -> togglePlayerControlVisibility()); | ||
|
||
playerControlView = findViewById(R.id.player_controls); | ||
playerControlView.setPlayer(player); | ||
// Set the fullscreen button to "close fullscreen" icon | ||
ImageView fullscreenIcon = playerControlView.findViewById(R.id.exo_fullscreen_icon); | ||
fullscreenIcon.setImageResource(R.drawable.exo_controls_fullscreen_exit); | ||
playerControlView.findViewById(R.id.exo_fullscreen_button) | ||
.setOnClickListener(v -> { | ||
if (exoplayerView != null) { | ||
exoplayerView.setFullscreen(false); | ||
} | ||
}); | ||
//Handling the playButton click event | ||
playerControlView.findViewById(R.id.exo_play).setOnClickListener(v -> { | ||
if (player != null && player.getPlaybackState() == Player.STATE_ENDED) { | ||
player.seekTo(0); | ||
} | ||
if (exoplayerView != null) { | ||
exoplayerView.setPausedModifier(false); | ||
} | ||
}); | ||
|
||
//Handling the pauseButton click event | ||
playerControlView.findViewById(R.id.exo_pause).setOnClickListener(v -> { | ||
if (exoplayerView != null) { | ||
exoplayerView.setPausedModifier(true); | ||
} | ||
}); | ||
} | ||
|
||
@Override | ||
public void onResume() { | ||
super.onResume(); | ||
if (exoplayerView != null) { | ||
exoplayerView.syncPlayerState(); | ||
exoplayerView.registerFullScreenDelegate(this); | ||
} | ||
} | ||
|
||
@Override | ||
public void onPause() { | ||
super.onPause(); | ||
player.setPlayWhenReady(false); | ||
if (exoplayerView != null) { | ||
exoplayerView.registerFullScreenDelegate(null); | ||
} | ||
} | ||
|
||
@Override | ||
public void onWindowFocusChanged(boolean hasFocus) { | ||
super.onWindowFocusChanged(hasFocus); | ||
if (hasFocus) { | ||
playerControlView.postDelayed(this::hideSystemUI, 200); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
if ((keyCode == KeyEvent.KEYCODE_BACK)) { | ||
if (exoplayerView != null) { | ||
exoplayerView.setFullscreen(false); | ||
return false; | ||
} | ||
return true; | ||
} | ||
return super.onKeyDown(keyCode, event); | ||
} | ||
|
||
private void togglePlayerControlVisibility() { | ||
if (playerControlView.isVisible()) { | ||
playerControlView.hide(); | ||
} else { | ||
playerControlView.show(); | ||
} | ||
} | ||
|
||
/** | ||
* Enables regular immersive mode. | ||
*/ | ||
private void hideSystemUI() { | ||
View decorView = getWindow().getDecorView(); | ||
decorView.setSystemUiVisibility( | ||
View.SYSTEM_UI_FLAG_IMMERSIVE | ||
// Set the content to appear under the system bars so that the | ||
// content doesn't resize when the system bars hide and show. | ||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE | ||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | ||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | ||
// Hide the nav bar and status bar | ||
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | ||
| View.SYSTEM_UI_FLAG_FULLSCREEN); | ||
} | ||
|
||
/** | ||
* Shows the system bars by removing all the flags | ||
* except for the ones that make the content appear under the system bars. | ||
*/ | ||
private void showSystemUI() { | ||
View decorView = getWindow().getDecorView(); | ||
decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | ||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | ||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); | ||
} | ||
|
||
@Override | ||
public void closeFullScreen() { | ||
finish(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.