Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix UninitializedPropertyAccessException when destroying the Player #598

Merged
merged 3 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
}
strangesource marked this conversation as resolved.
Show resolved Hide resolved
}

Expand Down
Loading