From a89edcc1d5ab51cd475aa6406dfffe57e262f260 Mon Sep 17 00:00:00 2001 From: Matthias Tamegger Date: Wed, 15 Nov 2023 13:07:51 +0100 Subject: [PATCH 1/5] fix(android): decouple the player life cycle handling from the RNPlayerView --- .../com/bitmovin/player/reactnative/RNPlayerView.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt index d3c18ca0..e871ef07 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt @@ -186,10 +186,15 @@ class RNPlayerView( * Cleans up the resources and listeners produced by this view. */ fun dispose() { - viewEventRelay.eventEmitter = null - playerEventRelay.eventEmitter = null - playerView?.removeOnLayoutChangeListener(this) - playerView?.onDestroy() + _playerView?.run { + removeOnLayoutChangeListener(this@RNPlayerView) + // The `RNPlayerView` should not take care of the player lifecycle. + // As a different component is creating the player instance, the other component + // is responsible for destroying the player in the end. + player = null + onDestroy() + } + _playerView = null activityLifecycle.removeObserver(activityLifecycleObserver) } From e842e92e0aea3110814f98a2885d8cb56ddc1bd7 Mon Sep 17 00:00:00 2001 From: Matthias Tamegger Date: Wed, 15 Nov 2023 13:10:12 +0100 Subject: [PATCH 2/5] chore(android): add changelog entry --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index ec0a1aa6..857820bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Fixed + +- Android: `PlayerView` destroys attached `Player` instance on destroy. `Player` life cycle must be handled on the creation side + ## [0.14.0] (2023-11-14) ### Added From ebd580ae7af786bdb422ae054258ef0d33b0aeec Mon Sep 17 00:00:00 2001 From: Matthias Tamegger Date: Thu, 16 Nov 2023 11:22:11 +0100 Subject: [PATCH 3/5] chore(android): restructure code block --- .../player/reactnative/RNPlayerView.kt | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt index e871ef07..6cf26724 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt @@ -157,8 +157,7 @@ class RNPlayerView( /** * Associated Bitmovin's `PlayerView`. */ - val playerView: PlayerView? - get() = _playerView + val playerView: PlayerView? get() = _playerView private var subtitleView: SubtitleView? = null @@ -186,16 +185,16 @@ class RNPlayerView( * Cleans up the resources and listeners produced by this view. */ fun dispose() { - _playerView?.run { - removeOnLayoutChangeListener(this@RNPlayerView) - // The `RNPlayerView` should not take care of the player lifecycle. - // As a different component is creating the player instance, the other component - // is responsible for destroying the player in the end. - player = null - onDestroy() - } - _playerView = null activityLifecycle.removeObserver(activityLifecycleObserver) + + val playerView = _playerView ?: return + _playerView = null + // The `RNPlayerView` should not take care of the player lifecycle. + // As a different component is creating the player instance, the other component + // is responsible for destroying the player in the end. + playerView.player = null + playerView.removeOnLayoutChangeListener(this) + playerView.onDestroy() } /** From beb7519a6a67603c35b986bffd8d2b04fa93e66e Mon Sep 17 00:00:00 2001 From: Matthias Tamegger Date: Thu, 16 Nov 2023 11:25:26 +0100 Subject: [PATCH 4/5] fix(android): move cleanup code to setter --- .../main/java/com/bitmovin/player/reactnative/RNPlayerView.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt index 6cf26724..c2d166e7 100644 --- a/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt +++ b/android/src/main/java/com/bitmovin/player/reactnative/RNPlayerView.kt @@ -149,6 +149,7 @@ class RNPlayerView( private var _playerView: PlayerView? = null set(value) { + field?.removeOnLayoutChangeListener(this) field = value viewEventRelay.eventEmitter = field playerEventRelay.eventEmitter = field?.player @@ -193,7 +194,6 @@ class RNPlayerView( // As a different component is creating the player instance, the other component // is responsible for destroying the player in the end. playerView.player = null - playerView.removeOnLayoutChangeListener(this) playerView.onDestroy() } From 2c29de123fd56a04c5cb85c54d3fc226b23eee79 Mon Sep 17 00:00:00 2001 From: Matthias Tamegger Date: Thu, 16 Nov 2023 11:26:35 +0100 Subject: [PATCH 5/5] chore(android): adjust changelog wording --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 857820bd..13315841 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ### Fixed -- Android: `PlayerView` destroys attached `Player` instance on destroy. `Player` life cycle must be handled on the creation side +- Android: `PlayerView` destroys attached `Player` instance on destroy. `Player` lifecycle must be handled on the creation side ## [0.14.0] (2023-11-14)