Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ actual class SoundEffectPool actual constructor(concurrency: Int) {
if (field == value) return
field = value
if (value) {
soundPool.pause(streamId)
} else {
soundPool.resume(streamId)
} else {
soundPool.pause(streamId)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ actual suspend fun AudioSource.load(): PlayableAudio {
override fun audioPlayerDidFinishPlaying(player: AVAudioPlayer, successfully: Boolean) {
weakSelf.get()?.let { audio ->
audio.onCompleteHandler?.invoke()
audio.isPlaying = false
// println("keepAlive.remove($audio)")
keepAlive.remove(audio)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,47 +99,63 @@ actual class RawVideoView actual constructor(
updateSourceDurationFromPlayer(controller.player)
value?.let { player ->
val weakPlayer = WeakReference(player)
val weakSelf = WeakReference(this)

playerRateObservationClose = player.observe("rate") {
val self = weakSelf.get() ?: return@observe
val player = weakPlayer.get() ?: return@observe

val value = player.rate > 0f
if (shouldPlay && !value) _completedPlay.invokeAll()
if (!value && loop && shouldPlay) {
controller.player?.seekToTime(CMTimeMake(0.toLong(), 1000))
controller.player?.play()
if (!_playing.value) _playing.value = true

if (self.shouldPlay && !value) {
self._completedPlay.invokeAll()
}

if (!value && self.loop && self.shouldPlay) {
self.controller.player?.seekToTime(CMTimeMake(0, 1000))
self.controller.player?.play()
if (!self._playing.value) self._playing.value = true
} else {
if (_playing.value != value) _playing.value = value
if (self._playing.value != value) {
self._playing.value = value
}

if (player.rate > 0f) {
animationFrameRateClose = AppState.animationFrame.addListener {
_time.value = CMTimeGetSeconds(player.currentTime()).seconds
self.animationFrameRateClose = AppState.animationFrame.addListener {
val s = weakSelf.get() ?: return@addListener
val p = weakPlayer.get() ?: return@addListener
s._time.value = CMTimeGetSeconds(p.currentTime()).seconds
}
} else {
animationFrameRateClose?.invoke()
animationFrameRateClose = null
self.animationFrameRateClose?.invoke()
self.animationFrameRateClose = null
}
}
}

volumeObservationClose = player.observe("volume") {
val self = weakSelf.get() ?: return@observe
val player = weakPlayer.get() ?: return@observe
val value = player.volume
_volume.value = value

self._volume.value = player.volume
}

playerStatusObservationClose = player.observe("status") {
val self = weakSelf.get() ?: return@observe
val p = weakPlayer.get() ?: return@observe

when (p.status) {
AVPlayerStatusReadyToPlay -> {
_state.state = ReactiveState(Unit)
// Duration becomes available when ready
updateSourceDurationFromPlayer(p)
self._state.state = ReactiveState(Unit)
self.updateSourceDurationFromPlayer(p)
}
AVPlayerStatusFailed -> {
val message = p.error?.localizedDescription ?: "Video failed to load"
_state.state = ReactiveState.exception(Exception(message))
self._state.state = ReactiveState.exception(Exception(message))
}
else -> {}
}
}
// endObservationClose =
}
}

Expand Down Expand Up @@ -207,13 +223,17 @@ actual class RawVideoView actual constructor(

// Clean up observers and resources when view is removed
onRemove {
controller.player?.pause()
controller.player?.replaceCurrentItemWithPlayerItem(null)

NSNotificationCenter.defaultCenter.removeObserver(playerCallbackHolder)
playerRateObservationClose?.invoke()
volumeObservationClose?.invoke()
endObservationClose?.invoke()
playerStatusObservationClose?.invoke()
animationFrameRateClose?.invoke()
controller.player = null
println("AFTER REMOVE: player = ${controller.player}")
}
launch {
println("AVPlayerStatusUnknown: $AVPlayerStatusUnknown")
Expand Down
Loading