update fullscreen activity
This commit is contained in:
parent
32880544e5
commit
0b7ea71d77
@ -3,6 +3,7 @@
|
||||
<application>
|
||||
<activity
|
||||
android:name="com.brentvatne.exoplayer.ExoPlayerFullscreenVideoActivity"
|
||||
android:configChanges="orientation|keyboardHidden|screenSize" />
|
||||
android:configChanges="orientation|keyboardHidden|screenSize"
|
||||
android:launchMode="singleTop" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.brentvatne.exoplayer;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.KeyEvent;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
@ -13,7 +14,6 @@ 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_IS_PLAYING = "extra_is_playing";
|
||||
|
||||
private int id;
|
||||
private PlayerControlView playerControlView;
|
||||
@ -36,26 +36,40 @@ public class ExoPlayerFullscreenVideoActivity extends AppCompatActivity implemen
|
||||
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 -> finish());
|
||||
.setOnClickListener(v -> ReactExoplayerView.getViewInstance(id).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);
|
||||
}
|
||||
ReactExoplayerView.getViewInstance(id).setPausedModifier(false);
|
||||
});
|
||||
|
||||
//Handling the pauseButton click event
|
||||
playerControlView.findViewById(R.id.exo_pause).setOnClickListener(v -> ReactExoplayerView.getViewInstance(id).setPausedModifier(true));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
boolean isPlaying = getIntent().getBooleanExtra(EXTRA_IS_PLAYING, false);
|
||||
player.setPlayWhenReady(isPlaying);
|
||||
boolean isPaused = ReactExoplayerView.getViewInstance(id).isPaused();
|
||||
player.setPlayWhenReady(!isPaused);
|
||||
ReactExoplayerView.getViewInstance(id).registerFullScreenDelegate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
boolean isPlaying = player.getPlayWhenReady() && player.getPlaybackState() == Player.STATE_READY;
|
||||
ReactExoplayerView.getViewInstance(id).setPausedModifier(!isPlaying);
|
||||
player.setPlayWhenReady(false);
|
||||
ReactExoplayerView.getViewInstance(id).registerFullScreenDelegate(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
ReactExoplayerView.getViewInstance(id).removeViewInstance();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWindowFocusChanged(boolean hasFocus) {
|
||||
super.onWindowFocusChanged(hasFocus);
|
||||
@ -64,6 +78,15 @@ 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;
|
||||
}
|
||||
return super.onKeyDown(keyCode, event);
|
||||
}
|
||||
|
||||
private void togglePlayerControlVisibility() {
|
||||
if (playerControlView.isVisible()) {
|
||||
playerControlView.hide();
|
||||
|
@ -239,9 +239,13 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
@Override
|
||||
public void onHostResume() {
|
||||
exoPlayerView.setPlayer(player);
|
||||
if (!playInBackground || !isInBackground) {
|
||||
setPlayWhenReady(!isPaused);
|
||||
if (player != null) {
|
||||
exoPlayerView.setPlayer(player);
|
||||
boolean temp = this.disableFocus;
|
||||
player.setPlayWhenReady(!isPaused);
|
||||
this.disableFocus = temp;
|
||||
}
|
||||
}
|
||||
isInBackground = false;
|
||||
}
|
||||
@ -296,6 +300,10 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
this.fullScreenDelegate = delegate;
|
||||
}
|
||||
|
||||
public void removeViewInstance() {
|
||||
instances.remove(uid);
|
||||
}
|
||||
|
||||
// Internal methods
|
||||
|
||||
/**
|
||||
@ -315,8 +323,6 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
instances.put(uid, this);
|
||||
Intent intent = new Intent(getContext(), ExoPlayerFullscreenVideoActivity.class);
|
||||
intent.putExtra(ExoPlayerFullscreenVideoActivity.EXTRA_ID, this.uid);
|
||||
boolean isPlaying = player.getPlayWhenReady() && player.getPlaybackState() == Player.STATE_READY;
|
||||
intent.putExtra(ExoPlayerFullscreenVideoActivity.EXTRA_IS_PLAYING, isPlaying);
|
||||
getContext().startActivity(intent);
|
||||
}
|
||||
|
||||
@ -332,7 +338,7 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
playerControlView.setPlayer(player);
|
||||
playerControlView.show();
|
||||
playPauseControlContainer = playerControlView.findViewById(R.id.exo_play_pause_container);
|
||||
playerControlView.findViewById(R.id.exo_fullscreen_button).setOnClickListener(v -> showFullscreen());
|
||||
playerControlView.findViewById(R.id.exo_fullscreen_button).setOnClickListener(v -> setFullscreen(true));
|
||||
|
||||
// Invoking onClick event for exoplayerView
|
||||
exoPlayerView.setOnClickListener(new OnClickListener() {
|
||||
|
Loading…
Reference in New Issue
Block a user