Skip to content

Commit

Permalink
make ui state hold available tracks
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Oct 15, 2024
1 parent f9f5953 commit 1f101d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.utils.Chapter
import net.newpipe.newplayer.RepeatMode
import net.newpipe.newplayer.ui.ContentScale
import net.newpipe.newplayer.utils.AudioStreamTrack
import net.newpipe.newplayer.utils.LanguageIdentifier
import net.newpipe.newplayer.utils.StreamTrack
import net.newpipe.newplayer.utils.VideoStreamTrack


@UnstableApi
Expand All @@ -54,13 +57,10 @@ data class NewPlayerUIState(
val playListDurationInS: Int,
val currentlyPlaying: MediaItem?,
val currentPlaylistItemIndex: Int,
val availableStreamVariants: List<String>,
val availableLanguages: List<String>,
val availableSubtitles: List<String>,
val currentlyAvailableTracks: List<StreamTrack>,
val enteringPip: Boolean,
val currentSeekPreviewThumbnail: ImageBitmap?,
val seekPreviewVisible: Boolean,
val currentlyAvailableTracks: List<StreamTrack>
) {
companion object {
val DEFAULT = NewPlayerUIState(
Expand All @@ -86,19 +86,20 @@ data class NewPlayerUIState(
playListDurationInS = 0,
currentlyPlaying = null,
currentPlaylistItemIndex = 0,
availableLanguages = emptyList(),
availableSubtitles = emptyList(),
availableStreamVariants = emptyList(),
currentlyAvailableTracks = emptyList(),
enteringPip = false,
currentSeekPreviewThumbnail = null,
seekPreviewVisible = false,
currentlyAvailableTracks = emptyList()
)

val DUMMY = DEFAULT.copy(
availableLanguages = listOf("German", "English", "Spanish"),
availableSubtitles = listOf("German", "English", "Spanish"),
availableStreamVariants = listOf("460p", "720p", "1080p60"),
currentlyAvailableTracks = listOf(
VideoStreamTrack(width= 1920, height = 1080, frameRate = 30, fileFormat = "MPEG4"),
VideoStreamTrack(width= 1280, height = 720, frameRate = 30, fileFormat = "MPEG4"),
VideoStreamTrack(width= 853, height = 480, frameRate = 30, fileFormat = "MPEG4"),
AudioStreamTrack(bitrate = 49000, language = LanguageIdentifier.EN, fileFormat = "MP4A"),
AudioStreamTrack(bitrate = 49000, language = LanguageIdentifier.ES, fileFormat = "MP4A")
),
uiMode = UIModeState.EMBEDDED_VIDEO,
playing = true,
seekerPosition = 0.3f,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import net.newpipe.newplayer.utils.NewPlayerException
import net.newpipe.newplayer.PlayMode
import net.newpipe.newplayer.RepeatMode
import net.newpipe.newplayer.ui.ContentScale
import net.newpipe.newplayer.utils.TrackSelector
import java.util.LinkedList
import kotlin.math.abs

Expand Down Expand Up @@ -244,16 +245,11 @@ class NewPlayerViewModelImpl @Inject constructor(
}

viewModelScope.launch {
newPlayer.currentlyAvailableTracks.collect { availableStreams ->
if (availableStreams != null) {
/*TODO*/
} else {
mutableUiState.update {
it.copy(
availableLanguages = emptyList(),
availableStreamVariants = emptyList()
)
}
newPlayer.currentlyAvailableTracks.collect { availableTracks ->
mutableUiState.update {
it.copy(
currentlyAvailableTracks = availableTracks
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ internal class TrackSelector(
internal fun getNonDynamicTracksNonDuplicated(streams: List<Stream>) =
getAllAvailableTracksNonDuplicated(streams.filter { !it.isDashOrHls })

internal fun getAvailableLanguages(tracks: List<StreamTrack>) =
tracks.filterIsInstance<AudioStreamTrack>().map { it.language }.filterNotNull()

private fun getBestLanguageFit(
availableStreams: List<Stream>, preferredLanguages: List<LanguageIdentifier>
): LanguageIdentifier? {
Expand Down

0 comments on commit 1f101d8

Please sign in to comment.