Skip to content

Commit

Permalink
Fix UninitializedPropertyAccessException when destroying the Player (#…
Browse files Browse the repository at this point in the history
…598)

## Description
When a player with the config `mediaControlConfig.isEnabled = false` is
created and the player gets destroyed, it will throw an
`UninitializedPropertyAccessException` while trying to destroy the
`MediaSessionPlaybackManager`

## Changes
- Change `MediaSessionPlaybackManager.playerId` from `lateinit` to
nullable.
- Remove unnecessary `resolveOnUiThread` call

## Checklist
- [x] 🗒 `CHANGELOG` entry
  • Loading branch information
testcenter authored Jan 15, 2025
1 parent dedce28 commit c3a125d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## [Unreleased]

### Fixed

- Android: App crashes when `mediaControlConfig.isEnabled` is set to `false` and the player gets destroyed

## [0.36.0] - 2024-12-20

### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import com.facebook.react.bridge.*

class MediaSessionPlaybackManager(val context: ReactApplicationContext) {
private var serviceBinder: MediaSessionPlaybackService.ServiceBinder? = null
private lateinit var playerId: NativeId
private var playerId: NativeId? = null
val player: Player?
get() = serviceBinder?.player

Expand All @@ -24,7 +24,9 @@ class MediaSessionPlaybackManager(val context: ReactApplicationContext) {
}

override fun onServiceDisconnected(name: ComponentName) {
destroy(playerId)
playerId?.let {
destroy(it)
}
}
}

Expand All @@ -38,13 +40,16 @@ class MediaSessionPlaybackManager(val context: ReactApplicationContext) {
}

fun destroy(nativeId: NativeId) {
if (nativeId != playerId) { return }
if (nativeId != playerId) {
return
}
serviceBinder?.player = null
serviceBinder = null
}

private fun getPlayer(
nativeId: NativeId = playerId,
nativeId: NativeId? = playerId,
playerModule: PlayerModule? = context.playerModule,
): Player = playerModule?.getPlayerOrNull(nativeId) ?: throw IllegalArgumentException("Invalid PlayerId $nativeId")
): Player = nativeId?.let { playerModule?.getPlayerOrNull(nativeId) }
?: throw IllegalArgumentException("Invalid PlayerId $nativeId")
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,7 @@ class PlayerModule(context: ReactApplicationContext) : BitmovinBaseModule(contex
}

if (enableMediaSession) {
promise.unit.resolveOnUiThread {
mediaSessionPlaybackManager.setupMediaSessionPlayback(nativeId)
}
mediaSessionPlaybackManager.setupMediaSessionPlayback(nativeId)
}
}

Expand Down

0 comments on commit c3a125d

Please sign in to comment.