Skip to content
This repository was archived by the owner on May 16, 2024. It is now read-only.

Commit ff1e24a

Browse files
committed
fix: ensure view drop stop playback startup (TheWidlarzGroup#3875)
1 parent 7133c96 commit ff1e24a

File tree

3 files changed

+26
-5
lines changed

3 files changed

+26
-5
lines changed

android/src/main/java/com/brentvatne/exoplayer/ReactExoplayerView.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ public class ReactExoplayerView extends FrameLayout implements
258258
private long lastBufferDuration = -1;
259259
private long lastDuration = -1;
260260

261+
private boolean viewHasDropped = false;
261262
private void updateProgress() {
262263
if (player != null) {
263264
if (playerControlView != null && isPlayingAd() && controls) {
@@ -375,6 +376,8 @@ protected void onDetachedFromWindow() {
375376
public void cleanUpResources() {
376377
stopPlayback();
377378
themedReactContext.removeLifecycleEventListener(this);
379+
releasePlayer();
380+
viewHasDropped = true;
378381
}
379382

380383
//BandwidthMeter.EventListener implementation
@@ -647,6 +650,9 @@ private void initializePlayer() {
647650
Activity activity = themedReactContext.getCurrentActivity();
648651
// This ensures all props have been settled, to avoid async racing conditions.
649652
mainRunnable = () -> {
653+
if (viewHasDropped) {
654+
return;
655+
}
650656
try {
651657
if (player == null) {
652658
// Initialize core configuration and listeners
@@ -658,7 +664,9 @@ private void initializePlayer() {
658664
ExecutorService es = Executors.newSingleThreadExecutor();
659665
es.execute(() -> {
660666
// DRM initialization must run on a different thread
661-
667+
if (viewHasDropped) {
668+
return;
669+
}
662670
if (activity == null) {
663671
DebugLog.e(TAG, "Failed to initialize Player!, null activity");
664672
eventEmitter.error("Failed to initialize Player!", new Exception("Current Activity is null!"), "1001");
@@ -667,12 +675,15 @@ private void initializePlayer() {
667675

668676
// Initialize handler to run on the main thread
669677
activity.runOnUiThread(() -> {
678+
if (viewHasDropped) {
679+
return;
680+
}
670681
try {
671682
// Source initialization must run on the main thread
672683
initializePlayerSource();
673684
} catch (Exception ex) {
674685
self.playerNeedsSource = true;
675-
DebugLog.e(TAG, "Failed to initialize Player!");
686+
DebugLog.e(TAG, "Failed to initialize Player! 1");
676687
DebugLog.e(TAG, ex.toString());
677688
ex.printStackTrace();
678689
self.eventEmitter.error(ex.toString(), ex, "1001");
@@ -684,7 +695,7 @@ private void initializePlayer() {
684695
}
685696
} catch (Exception ex) {
686697
self.playerNeedsSource = true;
687-
DebugLog.e(TAG, "Failed to initialize Player!");
698+
DebugLog.e(TAG, "Failed to initialize Player! 2");
688699
DebugLog.e(TAG, ex.toString());
689700
ex.printStackTrace();
690701
eventEmitter.error(ex.toString(), ex, "1001");

ios/Video/NowPlayingInfoCenterManager.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ class NowPlayingInfoCenterManager {
6161
return
6262
}
6363

64-
if let observer = observers[players.hashValue] {
64+
if let observer = observers[player.hashValue] {
6565
observer.invalidate()
6666
}
6767

68-
observers.removeValue(forKey: players.hashValue)
68+
observers.removeValue(forKey: player.hashValue)
6969
players.remove(player)
7070

7171
if currentPlayer == player {

ios/Video/RCTVideo.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1241,17 +1241,27 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
12411241
// MARK: - Lifecycle
12421242

12431243
override func removeFromSuperview() {
1244+
self._player?.replaceCurrentItem(with: nil)
12441245
if let player = _player {
12451246
player.pause()
12461247
NowPlayingInfoCenterManager.shared.removePlayer(player: player)
12471248
}
1249+
_playerItem = nil
1250+
_source = nil
1251+
_chapters = nil
1252+
_drm = nil
1253+
_textTracks = nil
1254+
_selectedTextTrackCriteria = nil
1255+
_selectedAudioTrackCriteria = nil
1256+
_presentingViewController = nil
12481257

12491258
_player = nil
12501259
_resouceLoaderDelegate = nil
12511260
_playerObserver.clearPlayer()
12521261

12531262
#if USE_GOOGLE_IMA
12541263
_imaAdsManager.releaseAds()
1264+
_imaAdsManager = nil
12551265
#endif
12561266

12571267
self.removePlayerLayer()

0 commit comments

Comments
 (0)