From 5f5ebe7dd105f58bdb364106b73897d9650722e9 Mon Sep 17 00:00:00 2001 From: Christian Schabesberger Date: Thu, 17 Oct 2024 21:24:04 +0200 Subject: [PATCH] add more filters to trackutils --- .../logic/ConstraintStreamSelector.kt | 11 ++++++- .../net/newpipe/newplayer/logic/TrackUtils.kt | 33 +++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/new-player/src/main/java/net/newpipe/newplayer/logic/ConstraintStreamSelector.kt b/new-player/src/main/java/net/newpipe/newplayer/logic/ConstraintStreamSelector.kt index 85f5eef9..f250d52a 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/logic/ConstraintStreamSelector.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/logic/ConstraintStreamSelector.kt @@ -8,9 +8,18 @@ internal object ConstraintStreamSelector { fun selectStream( availableStreams: List, currentStreamSelection: StreamSelection, - currentlyPlayingTracks: List + currentlyPlayingTracks: List, + languageConstraint: String?, + trackConstraint: StreamTrack? ): StreamSelection { + val availableFilteredByLanguage = if (languageConstraint != null) + TrackUtils.filtersByLanguage(availableStreams, languageConstraint) + else + availableStreams + + + return currentStreamSelection } } \ No newline at end of file diff --git a/new-player/src/main/java/net/newpipe/newplayer/logic/TrackUtils.kt b/new-player/src/main/java/net/newpipe/newplayer/logic/TrackUtils.kt index 78d577ee..4c2af5d4 100644 --- a/new-player/src/main/java/net/newpipe/newplayer/logic/TrackUtils.kt +++ b/new-player/src/main/java/net/newpipe/newplayer/logic/TrackUtils.kt @@ -20,6 +20,7 @@ package net.newpipe.newplayer.logic +import android.provider.MediaStore.Video import android.util.Log import androidx.annotation.OptIn import androidx.media3.common.C @@ -135,12 +136,40 @@ object TrackUtils { return false } + internal fun getStreamMatchingAudioTrack( + availableStreams: List, + track: AudioStreamTrack, + matchLanguage: Boolean = true, + matchBitrate: Boolean = true, + matchFileFormat: Boolean = true, + ) = availableStreams.filterIsInstance() + .filter{!matchLanguage || it.language == track.language} + .filter{!matchBitrate || it.bitrate == track.bitrate} + .filter{!matchFileFormat || it.fileFormat == track.fileFormat} + + + internal fun getStreamsMatchingVideoTrack( + availableStreams: List, + track: VideoStreamTrack, + matchWidth: Boolean = true, + matchHeight: Boolean = true, + matchFrameRate: Boolean = true, + matchFileFormat: Boolean = true + ) = availableStreams.filterIsInstance() + .filter{!matchWidth || it.width == track.width} + .filter{!matchHeight || it.height == track.height} + .filter{!matchFrameRate || it.frameRate == track.frameRate} + .filter{!matchFileFormat || it.fileFormat == track.fileFormat} + @OptIn(UnstableApi::class) - internal fun streamTracksFromMedia3Tracks(media3Tracks: Tracks, onlySelectedTracks: Boolean = false): List { + internal fun streamTracksFromMedia3Tracks( + media3Tracks: Tracks, + onlySelectedTracks: Boolean = false + ): List { val tracks = mutableListOf() for (group in media3Tracks.groups) { for (i in 0 until group.length) { - if(onlySelectedTracks && group.isTrackSelected(i)) + if (onlySelectedTracks && group.isTrackSelected(i)) continue val format = group.getTrackFormat(i)