Skip to content

Commit

Permalink
Merge pull request #323 from bitmovin/decouple_player_view_and_player…
Browse files Browse the repository at this point in the history
…_lifecycle

Decouple player view and player lifecycle
  • Loading branch information
matamegger authored Nov 16, 2023
2 parents 2be9eb7 + 2c29de1 commit 77abf20
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## [Unreleased]

### Fixed

- Android: `PlayerView` destroys attached `Player` instance on destroy. `Player` lifecycle must be handled on the creation side

## [0.14.0] (2023-11-14)

### Added
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -157,8 +158,7 @@ class RNPlayerView(
/**
* Associated Bitmovin's `PlayerView`.
*/
val playerView: PlayerView?
get() = _playerView
val playerView: PlayerView? get() = _playerView

private var subtitleView: SubtitleView? = null

Expand Down Expand Up @@ -186,11 +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()
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.onDestroy()
}

/**
Expand Down

0 comments on commit 77abf20

Please sign in to comment.