Skip to content

Commit

Permalink
display currently playing track
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Oct 16, 2024
1 parent e14a599 commit dea4d9a
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,16 @@ private fun TrackSelectionMenu(viewModel: InternalNewPlayerViewModel, uiState: N
}

val context = LocalContext.current
val noOtherTracksText = stringResource(
id = R.string.no_other_tracks_available_toast
)


val availableVideoTracks =
uiState.currentlyAvailableTracks.filterIsInstance<VideoStreamTrack>()

Box {
val noOtherTracksText = stringResource(
id = R.string.no_other_tracks_available_toast
)

Button(
onClick = {
if (1 < availableVideoTracks.size) {
Expand All @@ -188,7 +190,14 @@ private fun TrackSelectionMenu(viewModel: InternalNewPlayerViewModel, uiState: N
),
) {
Text(
"1080p", fontWeight = FontWeight.Bold, modifier = Modifier.padding(0.dp)
try {
uiState.currentlyPlayingTracks.filterIsInstance<VideoStreamTrack>()[0]
.toShortIdentifierString()
} catch (_: IndexOutOfBoundsException) {
stringResource(R.string.loading)
},
fontWeight = FontWeight.Bold,
modifier = Modifier.padding(0.dp)
)
}
DropdownMenu(expanded = menuVisible, onDismissRequest = { menuVisible = false }) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ data class NewPlayerUIState(
val currentlyPlaying: MediaItem?,
val currentPlaylistItemIndex: Int,
val currentlyAvailableTracks: List<StreamTrack>,
val currentlyPlayingTracks: List<StreamTrack>,
val enteringPip: Boolean,
val currentSeekPreviewThumbnail: ImageBitmap?,
val seekPreviewVisible: Boolean,
Expand Down Expand Up @@ -86,6 +87,7 @@ data class NewPlayerUIState(
currentlyPlaying = null,
currentPlaylistItemIndex = 0,
currentlyAvailableTracks = emptyList(),
currentlyPlayingTracks = emptyList(),
enteringPip = false,
currentSeekPreviewThumbnail = null,
seekPreviewVisible = false,
Expand All @@ -99,6 +101,10 @@ data class NewPlayerUIState(
AudioStreamTrack(bitrate = 49000, language = "en", fileFormat = "MP4A"),
AudioStreamTrack(bitrate = 49000, language = "es", fileFormat = "MP4A")
),
currentlyPlayingTracks = listOf(
VideoStreamTrack(width= 1920, height = 1080, frameRate = 30, fileFormat = "MPEG4"),
AudioStreamTrack(bitrate = 49000, language = "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 @@ -254,6 +254,16 @@ class NewPlayerViewModelImpl @Inject constructor(
}
}

viewModelScope.launch {
newPlayer.currentlyPlayingTracks.collect { playingTracks ->
mutableUiState.update {
it.copy(
currentlyPlayingTracks = playingTracks
)
}
}
}

mutableUiState.update {
it.copy(
playing = newPlayer.exoPlayer.value?.isPlaying ?: false,
Expand Down
1 change: 1 addition & 0 deletions new-player/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,5 @@
<string name="playing_in_background">Playing in the background…</string>
<string name="seek_thumb_preview">Video seek preview thumbnail</string>a
<string name="no_other_tracks_available_toast">No other stream tracks available.</string>
<string name="loading">Loading</string>
</resources>

0 comments on commit dea4d9a

Please sign in to comment.