diff --git a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PlayerCallbackFlow.kt b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PlayerCallbackFlow.kt index 49bd84c79..fef11bd14 100644 --- a/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PlayerCallbackFlow.kt +++ b/pillarbox-player/src/main/java/ch/srgssr/pillarbox/player/PlayerCallbackFlow.kt @@ -26,9 +26,11 @@ import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.callbackFlow import kotlinx.coroutines.flow.distinctUntilChanged import kotlinx.coroutines.flow.emptyFlow +import kotlinx.coroutines.flow.filterNot import kotlinx.coroutines.flow.flowOf import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.merge +import kotlinx.coroutines.flow.onEmpty import kotlinx.coroutines.flow.transformLatest import kotlinx.coroutines.isActive import kotlin.time.Duration @@ -292,9 +294,13 @@ fun Player.videoSizeAsFlow(): Flow = callbackFlow { * * @param defaultAspectRatio Aspect ratio when [Player.getVideoSize] is unknown or audio. */ -fun Player.getAspectRatioAsFlow(defaultAspectRatio: Float): Flow = videoSizeAsFlow().map { - it.computeAspectRatio(defaultAspectRatio) -} +fun Player.getAspectRatioAsFlow(defaultAspectRatio: Float): Flow = + videoSizeAsFlow() + .filterNot { it == VideoSize.UNKNOWN } + .map { + it.computeAspectRatio(defaultAspectRatio) + } + .onEmpty { emit(defaultAspectRatio) } /** * Get track selection parameters as flow [Player.getTrackSelectionParameters]