fix: ensure view drop stop playback startup (#3875)
This commit is contained in:
@@ -258,6 +258,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
private long lastBufferDuration = -1;
|
||||
private long lastDuration = -1;
|
||||
|
||||
private boolean viewHasDropped = false;
|
||||
private void updateProgress() {
|
||||
if (player != null) {
|
||||
if (playerControlView != null && isPlayingAd() && controls) {
|
||||
@@ -375,6 +376,8 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
public void cleanUpResources() {
|
||||
stopPlayback();
|
||||
themedReactContext.removeLifecycleEventListener(this);
|
||||
releasePlayer();
|
||||
viewHasDropped = true;
|
||||
}
|
||||
|
||||
//BandwidthMeter.EventListener implementation
|
||||
@@ -647,6 +650,9 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
Activity activity = themedReactContext.getCurrentActivity();
|
||||
// This ensures all props have been settled, to avoid async racing conditions.
|
||||
mainRunnable = () -> {
|
||||
if (viewHasDropped) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
if (player == null) {
|
||||
// Initialize core configuration and listeners
|
||||
@@ -658,7 +664,9 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
ExecutorService es = Executors.newSingleThreadExecutor();
|
||||
es.execute(() -> {
|
||||
// DRM initialization must run on a different thread
|
||||
|
||||
if (viewHasDropped) {
|
||||
return;
|
||||
}
|
||||
if (activity == null) {
|
||||
DebugLog.e(TAG, "Failed to initialize Player!, null activity");
|
||||
eventEmitter.error("Failed to initialize Player!", new Exception("Current Activity is null!"), "1001");
|
||||
@@ -667,12 +675,15 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
|
||||
// Initialize handler to run on the main thread
|
||||
activity.runOnUiThread(() -> {
|
||||
if (viewHasDropped) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Source initialization must run on the main thread
|
||||
initializePlayerSource();
|
||||
} catch (Exception ex) {
|
||||
self.playerNeedsSource = true;
|
||||
DebugLog.e(TAG, "Failed to initialize Player!");
|
||||
DebugLog.e(TAG, "Failed to initialize Player! 1");
|
||||
DebugLog.e(TAG, ex.toString());
|
||||
ex.printStackTrace();
|
||||
self.eventEmitter.error(ex.toString(), ex, "1001");
|
||||
@@ -684,7 +695,7 @@ public class ReactExoplayerView extends FrameLayout implements
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
self.playerNeedsSource = true;
|
||||
DebugLog.e(TAG, "Failed to initialize Player!");
|
||||
DebugLog.e(TAG, "Failed to initialize Player! 2");
|
||||
DebugLog.e(TAG, ex.toString());
|
||||
ex.printStackTrace();
|
||||
eventEmitter.error(ex.toString(), ex, "1001");
|
||||
|
Reference in New Issue
Block a user