check null before trigger action
This commit is contained in:
parent
859a0b8447
commit
7373761a4c
@ -15,19 +15,23 @@ import com.google.android.exoplayer2.SimpleExoPlayer;
|
||||
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_EXO_PLAYER_VIEW_ID = "extra_id";
|
||||
public static final String EXTRA_ORIENTATION = "extra_orientation";
|
||||
|
||||
private int id;
|
||||
private ReactExoplayerView exoplayerView;
|
||||
private PlayerControlView playerControlView;
|
||||
private SimpleExoPlayer 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);
|
||||
|
||||
id = getIntent().getIntExtra(EXTRA_ID, -1);
|
||||
String orientation = getIntent().getStringExtra(EXTRA_ORIENTATION);
|
||||
if ("landscape".equals(orientation)) {
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
||||
@ -35,7 +39,7 @@ public class ExoPlayerFullscreenVideoActivity extends AppCompatActivity implemen
|
||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
|
||||
}
|
||||
setContentView(R.layout.exo_player_fullscreen_video);
|
||||
player = ReactExoplayerView.getViewInstance(id).getPlayer();
|
||||
player = exoplayerView.getPlayer();
|
||||
|
||||
ExoPlayerView playerView = findViewById(R.id.player_view);
|
||||
playerView.setPlayer(player);
|
||||
@ -47,25 +51,35 @@ 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 -> ReactExoplayerView.getViewInstance(id).setFullscreen(false));
|
||||
.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);
|
||||
}
|
||||
ReactExoplayerView.getViewInstance(id).setPausedModifier(false);
|
||||
if (exoplayerView != null) {
|
||||
exoplayerView.setPausedModifier(false);
|
||||
}
|
||||
});
|
||||
|
||||
//Handling the pauseButton click event
|
||||
playerControlView.findViewById(R.id.exo_pause).setOnClickListener(v -> ReactExoplayerView.getViewInstance(id).setPausedModifier(true));
|
||||
playerControlView.findViewById(R.id.exo_pause).setOnClickListener(v -> {
|
||||
if (exoplayerView != null) {
|
||||
exoplayerView.setPausedModifier(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (ReactExoplayerView.getViewInstance(id) != null) {
|
||||
ReactExoplayerView.getViewInstance(id).syncPlayerState();
|
||||
ReactExoplayerView.getViewInstance(id).registerFullScreenDelegate(this);
|
||||
if (exoplayerView != null) {
|
||||
exoplayerView.syncPlayerState();
|
||||
exoplayerView.registerFullScreenDelegate(this);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,8 +87,8 @@ public class ExoPlayerFullscreenVideoActivity extends AppCompatActivity implemen
|
||||
public void onPause() {
|
||||
super.onPause();
|
||||
player.setPlayWhenReady(false);
|
||||
if (ReactExoplayerView.getViewInstance(id) != null) {
|
||||
ReactExoplayerView.getViewInstance(id).registerFullScreenDelegate(null);
|
||||
if (exoplayerView != null) {
|
||||
exoplayerView.registerFullScreenDelegate(null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -89,8 +103,8 @@ public class ExoPlayerFullscreenVideoActivity extends AppCompatActivity implemen
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if ((keyCode == KeyEvent.KEYCODE_BACK)) {
|
||||
if (ReactExoplayerView.getViewInstance(id) != null) {
|
||||
ReactExoplayerView.getViewInstance(id).setFullscreen(false);
|
||||
if (exoplayerView != null) {
|
||||
exoplayerView.setFullscreen(false);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -29,7 +29,6 @@ import com.google.android.exoplayer2.C;
|
||||
import com.google.android.exoplayer2.DefaultLoadControl;
|
||||
import com.google.android.exoplayer2.DefaultRenderersFactory;
|
||||
import com.google.android.exoplayer2.ExoPlaybackException;
|
||||
import com.google.android.exoplayer2.ExoPlayerFactory;
|
||||
import com.google.android.exoplayer2.Format;
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
@ -38,7 +37,6 @@ import com.google.android.exoplayer2.Timeline;
|
||||
import com.google.android.exoplayer2.drm.DefaultDrmSessionManager;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionEventListener;
|
||||
import com.google.android.exoplayer2.drm.DrmSessionManager;
|
||||
import com.google.android.exoplayer2.drm.FrameworkMediaCrypto;
|
||||
import com.google.android.exoplayer2.drm.FrameworkMediaDrm;
|
||||
import com.google.android.exoplayer2.drm.HttpMediaDrmCallback;
|
||||
import com.google.android.exoplayer2.drm.UnsupportedDrmException;
|
||||
@ -60,8 +58,8 @@ import com.google.android.exoplayer2.source.smoothstreaming.DefaultSsChunkSource
|
||||
import com.google.android.exoplayer2.source.smoothstreaming.SsMediaSource;
|
||||
import com.google.android.exoplayer2.trackselection.AdaptiveTrackSelection;
|
||||
import com.google.android.exoplayer2.trackselection.DefaultTrackSelector;
|
||||
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
|
||||
import com.google.android.exoplayer2.trackselection.ExoTrackSelection;
|
||||
import com.google.android.exoplayer2.trackselection.MappingTrackSelector;
|
||||
import com.google.android.exoplayer2.trackselection.TrackSelectionArray;
|
||||
import com.google.android.exoplayer2.ui.PlayerControlView;
|
||||
import com.google.android.exoplayer2.upstream.BandwidthMeter;
|
||||
@ -77,8 +75,8 @@ import java.net.CookiePolicy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.UUID;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@SuppressLint("ViewConstructor")
|
||||
class ReactExoplayerView extends FrameLayout implements
|
||||
@ -101,8 +99,6 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
|
||||
private static Map<Integer, ReactExoplayerView> instances = new HashMap<>();
|
||||
private static int UNIQUE_ID = 0;
|
||||
private int uid = ++UNIQUE_ID;
|
||||
private FullScreenDelegate fullScreenDelegate;
|
||||
|
||||
private final VideoEventEmitter eventEmitter;
|
||||
@ -141,8 +137,6 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
private int bufferForPlaybackMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_MS;
|
||||
private int bufferForPlaybackAfterRebufferMs = DefaultLoadControl.DEFAULT_BUFFER_FOR_PLAYBACK_AFTER_REBUFFER_MS;
|
||||
|
||||
private Handler mainHandler;
|
||||
|
||||
// Props from React
|
||||
private Uri srcUri;
|
||||
private String extension;
|
||||
@ -233,8 +227,6 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
exoPlayerView.setLayoutParams(layoutParams);
|
||||
|
||||
addView(exoPlayerView, 0, layoutParams);
|
||||
|
||||
mainHandler = new Handler();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -286,7 +278,7 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
public void cleanUpResources() {
|
||||
stopPlayback();
|
||||
instances.remove(uid);
|
||||
instances.remove(this.getId());
|
||||
}
|
||||
|
||||
//BandwidthMeter.EventListener implementation
|
||||
@ -344,9 +336,9 @@ class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
|
||||
private void showFullscreen() {
|
||||
instances.put(uid, this);
|
||||
instances.put(this.getId(), this);
|
||||
Intent intent = new Intent(getContext(), ExoPlayerFullscreenVideoActivity.class);
|
||||
intent.putExtra(ExoPlayerFullscreenVideoActivity.EXTRA_ID, this.uid);
|
||||
intent.putExtra(ExoPlayerFullscreenVideoActivity.EXTRA_EXO_PLAYER_VIEW_ID, this.getId());
|
||||
intent.putExtra(ExoPlayerFullscreenVideoActivity.EXTRA_ORIENTATION, this.fullScreenOrientation);
|
||||
getContext().startActivity(intent);
|
||||
isInFullscreen = true;
|
||||
|
Loading…
Reference in New Issue
Block a user