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

Prevent crash in case of misuse of AudioEngine.asPlayer().release #529

Merged
merged 1 commit into from
Jun 7, 2024
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 @@ -179,6 +179,14 @@ public class ExoPlayerEngine private constructor(
private val _playback: MutableStateFlow<AudioEngine.Playback> =
MutableStateFlow(exoPlayer.playback)

private val sessionPlayer = object :
ForwardingPlayer(exoPlayer) {

override fun release() {
// This object does not own the ExoAudiobookPlayer instance, do not close it.
}
}

init {
coroutineScope.launch {
val positionRefreshDelay = (1.0 / configuration.positionRefreshRate.value).seconds
Expand Down Expand Up @@ -227,7 +235,7 @@ public class ExoPlayerEngine private constructor(
}

override fun asPlayer(): Player {
return exoPlayer
return sessionPlayer
}

override fun submitPreferences(preferences: ExoPlayerPreferences) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ public interface AudioEngine<S : Configurable.Settings, P : Configurable.Prefere
/**
* The player is ready to play.
*/
public object Ready : State()
public data object Ready : State()

/**
* The end of the content has been reached.
*/
public object Ended : State()
public data object Ended : State()

/**
* The engine cannot play because the buffer is starved.
*/
public object Buffering : State()
public data object Buffering : State()

/**
* The engine cannot play because an error occurred.
*/
public data class Failure(val error: AudioEngine.Error) : State()
public data class Failure(val error: Error) : State()
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ package org.readium.navigator.media.tts
import org.readium.r2.navigator.preferences.Configurable
import org.readium.r2.shared.ExperimentalReadiumApi
import org.readium.r2.shared.util.Closeable
import org.readium.r2.shared.util.Error
import org.readium.r2.shared.util.Language

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public class TtsNavigator<S : TtsEngine.Settings, P : TtsEngine.Preferences<P>,

public sealed class State {

public object Ready : MediaNavigator.State.Ready
public data object Ready : MediaNavigator.State.Ready

public object Ended : MediaNavigator.State.Ended
public data object Ended : MediaNavigator.State.Ended

public data class Failure(val error: Error) : MediaNavigator.State.Failure
}
Expand Down
Loading