Skip to content

Commit

Permalink
add more filters to trackutils
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Oct 17, 2024
1 parent ae9fbda commit 5f5ebe7
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ internal object ConstraintStreamSelector {
fun selectStream(
availableStreams: List<Stream>,
currentStreamSelection: StreamSelection,
currentlyPlayingTracks: List<StreamTrack>
currentlyPlayingTracks: List<StreamTrack>,
languageConstraint: String?,
trackConstraint: StreamTrack?
): StreamSelection {

val availableFilteredByLanguage = if (languageConstraint != null)
TrackUtils.filtersByLanguage(availableStreams, languageConstraint)
else
availableStreams



return currentStreamSelection
}
}
33 changes: 31 additions & 2 deletions new-player/src/main/java/net/newpipe/newplayer/logic/TrackUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -135,12 +136,40 @@ object TrackUtils {
return false
}

internal fun getStreamMatchingAudioTrack(
availableStreams: List<Stream>,
track: AudioStreamTrack,
matchLanguage: Boolean = true,
matchBitrate: Boolean = true,
matchFileFormat: Boolean = true,
) = availableStreams.filterIsInstance<AudioStreamTrack>()
.filter{!matchLanguage || it.language == track.language}
.filter{!matchBitrate || it.bitrate == track.bitrate}
.filter{!matchFileFormat || it.fileFormat == track.fileFormat}


internal fun getStreamsMatchingVideoTrack(
availableStreams: List<Stream>,
track: VideoStreamTrack,
matchWidth: Boolean = true,
matchHeight: Boolean = true,
matchFrameRate: Boolean = true,
matchFileFormat: Boolean = true
) = availableStreams.filterIsInstance<VideoStreamTrack>()
.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<StreamTrack> {
internal fun streamTracksFromMedia3Tracks(
media3Tracks: Tracks,
onlySelectedTracks: Boolean = false
): List<StreamTrack> {
val tracks = mutableListOf<StreamTrack>()
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)
Expand Down

0 comments on commit 5f5ebe7

Please sign in to comment.