Skip to content

Commit

Permalink
Ignore unknown video size (#450)
Browse files Browse the repository at this point in the history
Co-authored-by: Gaëtan Muller <[email protected]>
  • Loading branch information
StaehliJ and MGaetan89 authored Feb 23, 2024
1 parent 8c1ea1b commit 5a3355f
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.callbackFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.filterNot
import kotlinx.coroutines.flow.flow
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
Expand Down Expand Up @@ -291,9 +293,13 @@ fun Player.videoSizeAsFlow(): Flow<VideoSize> = callbackFlow {
*
* @param defaultAspectRatio Aspect ratio when [Player.getVideoSize] is unknown or audio.
*/
fun Player.getAspectRatioAsFlow(defaultAspectRatio: Float): Flow<Float> = videoSizeAsFlow().map {
it.computeAspectRatio(defaultAspectRatio)
}
fun Player.getAspectRatioAsFlow(defaultAspectRatio: Float): Flow<Float> =
videoSizeAsFlow()
.filterNot { it == VideoSize.UNKNOWN }
.map {
it.computeAspectRatio(defaultAspectRatio)
}
.onEmpty { emit(defaultAspectRatio) }

/**
* Get track selection parameters as flow [Player.getTrackSelectionParameters]
Expand Down

0 comments on commit 5a3355f

Please sign in to comment.