Skip to content

Commit 970ee3e

Browse files
committed
Fix MediaPlayer snapshot threading in callbacks
1 parent 3f33800 commit 970ee3e

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

ui/revenuecatui/src/main/kotlin/com/revenuecat/purchases/ui/revenuecatui/components/video/MediaPlayerThreadOwner.kt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ internal class MediaPlayerThreadOwner(
126126
mediaPlayer.setOnPreparedListener { preparedPlayer ->
127127
if (released) return@setOnPreparedListener
128128
val activePlayer = preparedPlayer ?: return@setOnPreparedListener
129+
val videoWidth = getPlayerValue(activePlayer, 0) { currentPlayer -> currentPlayer.videoWidth }
130+
val videoHeight = getPlayerValue(activePlayer, 0) { currentPlayer -> currentPlayer.videoHeight }
129131
updatePlaybackSnapshot {
130132
it.copy(
131133
prepared = true,
@@ -140,7 +142,7 @@ internal class MediaPlayerThreadOwner(
140142
}
141143
mainHandler.post {
142144
if (!released) {
143-
onPrepared(activePlayer.videoWidth, activePlayer.videoHeight)
145+
onPrepared(videoWidth, videoHeight)
144146
}
145147
}
146148
}
@@ -236,14 +238,14 @@ internal class MediaPlayerThreadOwner(
236238
fun release() {
237239
if (released) return
238240
released = true
239-
updatePlaybackSnapshot {
240-
it.copy(
241-
prepared = false,
242-
isPlaying = false,
243-
)
244-
}
245241
workerHandler.removeCallbacksAndMessages(null)
246242
workerHandler.post {
243+
updatePlaybackSnapshot {
244+
it.copy(
245+
prepared = false,
246+
isPlaying = false,
247+
)
248+
}
247249
val mediaPlayer = player
248250
player = null
249251
currentSurface = null

0 commit comments

Comments
 (0)