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