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 cc7ecb5 commit fc689f6
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -292,9 +294,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 fc689f6

Please sign in to comment.