diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/metrics/MetricsOverlay.kt b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/metrics/MetricsOverlay.kt similarity index 93% rename from pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/metrics/MetricsOverlay.kt rename to pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/metrics/MetricsOverlay.kt index 857ed2d17..5e3235885 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/metrics/MetricsOverlay.kt +++ b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/metrics/MetricsOverlay.kt @@ -2,16 +2,15 @@ * Copyright (c) SRG SSR. All rights reserved. * License information is available from the LICENSE file. */ -package ch.srgssr.pillarbox.demo.ui.player.metrics +package ch.srgssr.pillarbox.demo.shared.ui.player.metrics import androidx.compose.foundation.layout.Column import androidx.compose.foundation.text.BasicText import androidx.compose.runtime.Composable import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color -import androidx.compose.ui.text.TextStyle +import androidx.compose.ui.graphics.Shadow import androidx.compose.ui.tooling.preview.Preview -import androidx.compose.ui.unit.sp import androidx.media3.common.Format import ch.srgssr.pillarbox.demo.shared.ui.settings.MetricsOverlayOptions import ch.srgssr.pillarbox.player.analytics.metrics.PlaybackMetrics @@ -108,7 +107,12 @@ private fun OverlayText( ) { BasicText( modifier = modifier, - style = TextStyle.Default.copy(fontSize = overlayOptions.textSize), + style = overlayOptions.textStyle.copy( + shadow = Shadow( + color = Color.Black, + blurRadius = 4f, + ), + ), color = { overlayOptions.textColor }, text = text, ) @@ -117,7 +121,7 @@ private fun OverlayText( @Preview @Composable private fun OverlayTextPreview() { - val overlayOptions = MetricsOverlayOptions(textColor = Color.Yellow, textSize = 12.sp) + val overlayOptions = MetricsOverlayOptions() OverlayText(text = "Text; 12 ac1.mp3 channels:4 colors:4", overlayOptions = overlayOptions) } diff --git a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/settings/PlayerSettingsViewModel.kt b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/settings/PlayerSettingsViewModel.kt index b4ac8681f..5f9f1b617 100644 --- a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/settings/PlayerSettingsViewModel.kt +++ b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/settings/PlayerSettingsViewModel.kt @@ -6,6 +6,7 @@ package ch.srgssr.pillarbox.demo.shared.ui.player.settings import android.app.Application import androidx.compose.material.icons.Icons +import androidx.compose.material.icons.filled.Analytics import androidx.compose.material.icons.filled.ClosedCaption import androidx.compose.material.icons.filled.RecordVoiceOver import androidx.compose.material.icons.filled.SlowMotionVideo @@ -16,7 +17,10 @@ import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope import androidx.media3.common.C import androidx.media3.common.Player +import androidx.media3.common.TrackSelectionParameters import ch.srgssr.pillarbox.demo.shared.R +import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettings +import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettingsRepository import ch.srgssr.pillarbox.player.extension.displayName import ch.srgssr.pillarbox.player.extension.getPlaybackSpeed import ch.srgssr.pillarbox.player.extension.isAudioTrackDisabled @@ -41,16 +45,19 @@ import kotlinx.coroutines.flow.SharingStarted import kotlinx.coroutines.flow.combine import kotlinx.coroutines.flow.map import kotlinx.coroutines.flow.stateIn +import kotlinx.coroutines.launch /** * Player settings view model * - * @constructor Create empty Player settings view model + * @constructor Create an empty Player settings `ViewModel` */ class PlayerSettingsViewModel( private val player: Player, - private val application: Application + private val application: Application, ) : AndroidViewModel(application) { + private val appSettingsRepository = AppSettingsRepository(application) + private val trackSelectionParameters = player.getTrackSelectionParametersAsFlow() .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), player.trackSelectionParameters) @@ -60,6 +67,9 @@ class PlayerSettingsViewModel( private val playbackSpeed = player.getPlaybackSpeedAsFlow() .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), player.getPlaybackSpeed()) + private val appSettings = appSettingsRepository.getAppSettings() + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), AppSettings()) + /** * All the available subtitle for the current [player]. */ @@ -128,7 +138,15 @@ class PlayerSettingsViewModel( videoTracks, trackSelectionParameters, playbackSpeed, - ) { subtitles, audioTracks, videoTracks, trackSelectionParameters, playbackSpeed -> + appSettings, + ) { settings -> + val subtitles = settings[SETTING_INDEX_SUBTITLES] as TracksSettingItem? + val audioTracks = settings[SETTING_INDEX_AUDIO_TRACKS] as TracksSettingItem? + val videoTracks = settings[SETTING_INDEX_VIDEO_TRACKS] as TracksSettingItem? + val trackSelectionParameters = settings[SETTING_INDEX_TRACK_SELECTION_PARAMETERS] as TrackSelectionParameters + val playbackSpeed = settings[SETTING_INDEX_PLAYBACK_SPEED] as Float + val appSettings = settings[SETTING_INDEX_APP_SETTINGS] as AppSettings + buildList { add( SettingItem( @@ -180,6 +198,19 @@ class PlayerSettingsViewModel( ) ) } + + add( + SettingItem( + title = application.getString(R.string.metrics_overlay), + subtitle = if (appSettings.metricsOverlayEnabled) { + application.getString(R.string.metrics_overlay_enabled) + } else { + application.getString(R.string.metrics_overlay_disabled) + }, + icon = Icons.Default.Analytics, + destination = SettingsRoutes.MetricsOverlay(appSettings.metricsOverlayEnabled), + ) + ) } }.stateIn(viewModelScope, SharingStarted.WhileSubscribed(), emptyList()) @@ -243,6 +274,17 @@ class PlayerSettingsViewModel( player.setPlaybackSpeed(playbackSpeed.rawSpeed) } + /** + * Enable or disable the metrics overlay. + * + * @param enabled + */ + fun setMetricsOverlayEnabled(enabled: Boolean) { + viewModelScope.launch { + appSettingsRepository.setMetricsOverlayEnabled(enabled) + } + } + private fun getTracksSubtitle( tracks: List, disabled: Boolean, @@ -252,8 +294,7 @@ class PlayerSettingsViewModel( } else { tracks.filter { it.isSelected } .map { it.format.displayName } - .filter { it != C.LANGUAGE_UNDETERMINED } - .firstOrNull() + .firstOrNull { it != C.LANGUAGE_UNDETERMINED } } } @@ -267,6 +308,13 @@ class PlayerSettingsViewModel( private companion object { private val speeds = floatArrayOf(0.25f, 0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f) + + private const val SETTING_INDEX_SUBTITLES = 0 + private const val SETTING_INDEX_AUDIO_TRACKS = 1 + private const val SETTING_INDEX_VIDEO_TRACKS = 2 + private const val SETTING_INDEX_TRACK_SELECTION_PARAMETERS = 3 + private const val SETTING_INDEX_PLAYBACK_SPEED = 4 + private const val SETTING_INDEX_APP_SETTINGS = 5 } /** @@ -274,7 +322,7 @@ class PlayerSettingsViewModel( * * @param player * @param application - * @constructor Create empty Factory + * @constructor Create an empty Factory */ @Suppress("UndocumentedPublicClass") class Factory( diff --git a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/settings/SettingsRoutes.kt b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/settings/SettingsRoutes.kt index 9da35c1be..84c6b7ef3 100644 --- a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/settings/SettingsRoutes.kt +++ b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/player/settings/SettingsRoutes.kt @@ -34,4 +34,13 @@ sealed class SettingsRoutes(val route: String) { * The route for the video track setting. */ data object VideoTrack : SettingsRoutes(route = "settings/video_track") + + /** + * The route for the metrics overlay setting. + * + * @property enabled Whether the metrics overlay is enabled. + */ + data class MetricsOverlay( + val enabled: Boolean, + ) : SettingsRoutes(route = "settings/metrics_overlay") } diff --git a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/AppSettings.kt b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/AppSettings.kt index 6e5fd3ea9..5e10f5205 100644 --- a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/AppSettings.kt +++ b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/AppSettings.kt @@ -5,8 +5,6 @@ package ch.srgssr.pillarbox.demo.shared.ui.settings import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.TextUnit -import androidx.compose.ui.unit.sp /** * App settings @@ -23,13 +21,11 @@ class AppSettings( /** * Text size - * - * @property size the [TextUnit]. */ - enum class TextSize(val size: TextUnit) { - Small(8.sp), - Medium(12.sp), - Large(18.sp), + enum class TextSize { + Small, + Medium, + Large, } /** diff --git a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/AppSettingsViewModel.kt b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/AppSettingsViewModel.kt index f72bb9be0..b0bfd3dee 100644 --- a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/AppSettingsViewModel.kt +++ b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/AppSettingsViewModel.kt @@ -7,6 +7,8 @@ package ch.srgssr.pillarbox.demo.shared.ui.settings import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModelProvider import androidx.lifecycle.viewModelScope +import kotlinx.coroutines.flow.SharingStarted +import kotlinx.coroutines.flow.stateIn import kotlinx.coroutines.launch /** @@ -20,6 +22,7 @@ class AppSettingsViewModel(private val appSettingsRepository: AppSettingsReposit * Current app settings */ val currentAppSettings = appSettingsRepository.getAppSettings() + .stateIn(viewModelScope, SharingStarted.WhileSubscribed(), AppSettings()) /** * Set metrics overlay enabled diff --git a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/MetricsOverlayOptions.kt b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/MetricsOverlayOptions.kt index 9073e9f91..f26a9e5a3 100644 --- a/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/MetricsOverlayOptions.kt +++ b/pillarbox-demo-shared/src/main/java/ch/srgssr/pillarbox/demo/shared/ui/settings/MetricsOverlayOptions.kt @@ -5,16 +5,15 @@ package ch.srgssr.pillarbox.demo.shared.ui.settings import androidx.compose.ui.graphics.Color -import androidx.compose.ui.unit.TextUnit +import androidx.compose.ui.text.TextStyle /** * Metrics overlay options * * @property textColor The [Color] for the text overlay. - * @property textSize The [TextUnit] for the text overlay. + * @property textStyle The [TextStyle] for the text overlay. */ - data class MetricsOverlayOptions( val textColor: Color = Color.Yellow, - val textSize: TextUnit = TextUnit.Unspecified, + val textStyle: TextStyle = TextStyle.Default, ) diff --git a/pillarbox-demo-shared/src/main/res/values/strings.xml b/pillarbox-demo-shared/src/main/res/values/strings.xml index 96fa8c1eb..cd2d4fc78 100644 --- a/pillarbox-demo-shared/src/main/res/values/strings.xml +++ b/pillarbox-demo-shared/src/main/res/values/strings.xml @@ -14,6 +14,9 @@ Settings Audio tracks Video tracks + Metrics Overlay + Enabled + Disabled Subtitles Speed Normal diff --git a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/PlayerActivity.kt b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/PlayerActivity.kt index b12940979..f58579bc1 100644 --- a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/PlayerActivity.kt +++ b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/PlayerActivity.kt @@ -9,11 +9,19 @@ import android.content.Intent import android.os.Bundle import androidx.activity.ComponentActivity import androidx.activity.compose.setContent +import androidx.activity.viewModels import androidx.compose.foundation.layout.fillMaxSize +import androidx.compose.runtime.collectAsState +import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.core.content.IntentCompat +import androidx.tv.material3.MaterialTheme import ch.srgssr.pillarbox.demo.shared.data.DemoItem import ch.srgssr.pillarbox.demo.shared.di.PlayerModule +import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettings +import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettingsRepository +import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettingsViewModel +import ch.srgssr.pillarbox.demo.shared.ui.settings.MetricsOverlayOptions import ch.srgssr.pillarbox.demo.tv.ui.player.compose.PlayerView import ch.srgssr.pillarbox.demo.tv.ui.theme.PillarboxTheme import ch.srgssr.pillarbox.player.PillarboxExoPlayer @@ -27,6 +35,9 @@ import ch.srgssr.pillarbox.player.session.PillarboxMediaSession class PlayerActivity : ComponentActivity() { private lateinit var player: PillarboxExoPlayer private lateinit var mediaSession: PillarboxMediaSession + private val appSettingsViewModel by viewModels { + AppSettingsViewModel.Factory(AppSettingsRepository(this)) + } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) @@ -45,9 +56,20 @@ class PlayerActivity : ComponentActivity() { setContent { PillarboxTheme { + val appSettings by appSettingsViewModel.currentAppSettings.collectAsState() + PlayerView( player = player, - modifier = Modifier.fillMaxSize() + modifier = Modifier.fillMaxSize(), + metricsOverlayEnabled = appSettings.metricsOverlayEnabled, + metricsOverlayOptions = MetricsOverlayOptions( + textColor = appSettings.metricsOverlayTextColor.color, + textStyle = when (appSettings.metricsOverlayTextSize) { + AppSettings.TextSize.Small -> MaterialTheme.typography.bodySmall + AppSettings.TextSize.Medium -> MaterialTheme.typography.bodyMedium + AppSettings.TextSize.Large -> MaterialTheme.typography.bodyLarge + }, + ), ) } } diff --git a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/PlayerView.kt b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/PlayerView.kt index 1e35d9124..94e4b83a6 100644 --- a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/PlayerView.kt +++ b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/PlayerView.kt @@ -26,6 +26,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Settings import androidx.compose.runtime.Composable import androidx.compose.runtime.LaunchedEffect +import androidx.compose.runtime.collectAsState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.remember @@ -50,10 +51,14 @@ import ch.srgssr.pillarbox.demo.shared.R import ch.srgssr.pillarbox.demo.shared.extension.onDpadEvent import ch.srgssr.pillarbox.demo.shared.ui.components.PillarboxSlider import ch.srgssr.pillarbox.demo.shared.ui.getFormatter +import ch.srgssr.pillarbox.demo.shared.ui.player.metrics.MetricsOverlay +import ch.srgssr.pillarbox.demo.shared.ui.settings.MetricsOverlayOptions import ch.srgssr.pillarbox.demo.tv.ui.player.compose.controls.PlayerError import ch.srgssr.pillarbox.demo.tv.ui.player.compose.controls.PlayerPlaybackRow import ch.srgssr.pillarbox.demo.tv.ui.player.compose.settings.PlaybackSettingsDrawer import ch.srgssr.pillarbox.demo.tv.ui.theme.paddings +import ch.srgssr.pillarbox.player.PillarboxExoPlayer +import ch.srgssr.pillarbox.player.currentPositionAsFlow import ch.srgssr.pillarbox.player.extension.canSeek import ch.srgssr.pillarbox.ui.extension.availableCommandsAsState import ch.srgssr.pillarbox.ui.extension.currentMediaMetadataAsState @@ -67,6 +72,7 @@ import ch.srgssr.pillarbox.ui.widget.maintainVisibleOnFocus import ch.srgssr.pillarbox.ui.widget.player.PlayerSurface import ch.srgssr.pillarbox.ui.widget.rememberDelayedVisibilityState import kotlinx.coroutines.delay +import kotlinx.coroutines.flow.map import kotlin.time.Duration.Companion.ZERO import kotlin.time.Duration.Companion.milliseconds import kotlin.time.Duration.Companion.seconds @@ -76,11 +82,15 @@ import kotlin.time.Duration.Companion.seconds * * @param player * @param modifier + * @param metricsOverlayEnabled + * @param metricsOverlayOptions */ @Composable fun PlayerView( - player: Player, - modifier: Modifier = Modifier + player: PillarboxExoPlayer, + modifier: Modifier = Modifier, + metricsOverlayEnabled: Boolean, + metricsOverlayOptions: MetricsOverlayOptions, ) { val drawerState = rememberDrawerState(initialValue = DrawerValue.Closed) val visibilityState = rememberDelayedVisibilityState(player = player, visible = true) @@ -126,10 +136,28 @@ fun PlayerView( Box(modifier = Modifier.fillMaxSize()) { val currentCredit by player.getCurrentCreditAsState() - ChapterInfo( - player = player, - visibilityState = visibilityState, - ) + Column { + ChapterInfo( + player = player, + visibilityState = visibilityState, + ) + + if (metricsOverlayEnabled) { + val currentMetricsFlow = remember(player) { + player.currentPositionAsFlow(updateInterval = 500.milliseconds) + .map { player.getCurrentMetrics() } + } + val currentMetrics by currentMetricsFlow.collectAsState(initial = player.getCurrentMetrics()) + + currentMetrics?.let { + MetricsOverlay( + playbackMetrics = it, + overlayOptions = metricsOverlayOptions, + modifier = Modifier.padding(MaterialTheme.paddings.small), + ) + } + } + } if (!visibilityState.isVisible && currentCredit != null) { SkipButton( diff --git a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/settings/PlaybackSettingsDrawer.kt b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/settings/PlaybackSettingsDrawer.kt index 01f796e05..01047ed33 100644 --- a/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/settings/PlaybackSettingsDrawer.kt +++ b/pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/ui/player/compose/settings/PlaybackSettingsDrawer.kt @@ -147,7 +147,13 @@ private fun NavigationDrawerScope.NavigationDrawerNavHost( items = settings, isItemSelected = { false }, onItemClick = { setting -> - navController.navigate(setting.destination.route) + val destination = setting.destination + + if (destination is SettingsRoutes.MetricsOverlay) { + settingsViewModel.setMetricsOverlayEnabled(!destination.enabled) + } else { + navController.navigate(destination.route) + } }, leadingContent = { setting -> Icon( diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/DemoPlayerView.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/DemoPlayerView.kt index 34854abfe..41090a668 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/DemoPlayerView.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/DemoPlayerView.kt @@ -20,12 +20,14 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.input.pointer.pointerInput import androidx.compose.ui.platform.LocalContext import androidx.lifecycle.compose.collectAsStateWithLifecycle +import androidx.lifecycle.viewmodel.compose.viewModel import androidx.media3.common.Player import androidx.navigation.compose.NavHost import androidx.navigation.compose.composable import androidx.navigation.compose.rememberNavController import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettings import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettingsRepository +import ch.srgssr.pillarbox.demo.shared.ui.settings.AppSettingsViewModel import ch.srgssr.pillarbox.demo.shared.ui.settings.MetricsOverlayOptions import ch.srgssr.pillarbox.demo.ui.components.ShowSystemUi import ch.srgssr.pillarbox.demo.ui.player.controls.PlayerBottomToolbar @@ -44,7 +46,7 @@ import com.google.accompanist.navigation.material.rememberBottomSheetNavigator * @param player The [Player] to observe. * @param modifier The modifier to be applied to the layout. * @param pictureInPicture The picture in picture state. - * @param pictureInPictureClick he picture in picture button action. If null no button. + * @param pictureInPictureClick The picture in picture button action. If `null` no button is displayed. * @param displayPlaylist If it displays playlist ui or not. */ @OptIn(ExperimentalMaterialNavigationApi::class) @@ -95,6 +97,9 @@ fun DemoPlayerView( @Composable private fun PlayerContent( player: Player, + appSettingsViewModel: AppSettingsViewModel = viewModel( + factory = AppSettingsViewModel.Factory(AppSettingsRepository(LocalContext.current)), + ), pictureInPicture: Boolean = false, pictureInPictureClick: (() -> Unit)? = null, displayPlaylist: Boolean = false, @@ -106,11 +111,7 @@ private fun PlayerContent( val fullScreenToggle: (Boolean) -> Unit = { fullScreenEnabled -> fullScreenState = fullScreenEnabled } - val context = LocalContext.current - val appSettingsRepository = remember { - AppSettingsRepository(context) - } - val appSettings by appSettingsRepository.getAppSettings().collectAsStateWithLifecycle(AppSettings()) + val appSettings by appSettingsViewModel.currentAppSettings.collectAsStateWithLifecycle() ShowSystemUi(isShowed = !fullScreenState) Column(modifier = Modifier.fillMaxSize()) { var pinchScaleMode by remember(fullScreenState) { @@ -141,7 +142,11 @@ private fun PlayerContent( overlayEnabled = appSettings.metricsOverlayEnabled, overlayOptions = MetricsOverlayOptions( textColor = appSettings.metricsOverlayTextColor.color, - textSize = appSettings.metricsOverlayTextSize.size + textStyle = when (appSettings.metricsOverlayTextSize) { + AppSettings.TextSize.Small -> MaterialTheme.typography.bodySmall + AppSettings.TextSize.Medium -> MaterialTheme.typography.bodyMedium + AppSettings.TextSize.Large -> MaterialTheme.typography.bodyLarge + }, ), ) { PlayerBottomToolbar( diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/PlayerView.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/PlayerView.kt index 7917e1b2c..d00c673e4 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/PlayerView.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/PlayerView.kt @@ -22,13 +22,13 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.zIndex import androidx.lifecycle.compose.collectAsStateWithLifecycle import androidx.media3.common.Player +import ch.srgssr.pillarbox.demo.shared.ui.player.metrics.MetricsOverlay import ch.srgssr.pillarbox.demo.shared.ui.settings.MetricsOverlayOptions import ch.srgssr.pillarbox.demo.ui.player.controls.PlayerControls import ch.srgssr.pillarbox.demo.ui.player.controls.PlayerError import ch.srgssr.pillarbox.demo.ui.player.controls.PlayerNoContent import ch.srgssr.pillarbox.demo.ui.player.controls.SkipButton import ch.srgssr.pillarbox.demo.ui.player.controls.rememberProgressTrackerState -import ch.srgssr.pillarbox.demo.ui.player.metrics.MetricsOverlay import ch.srgssr.pillarbox.demo.ui.theme.paddings import ch.srgssr.pillarbox.player.PillarboxExoPlayer import ch.srgssr.pillarbox.player.currentPositionAsFlow diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/settings/PlaybackSettingsContent.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/settings/PlaybackSettingsContent.kt index 685607588..f0f2a914e 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/settings/PlaybackSettingsContent.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/settings/PlaybackSettingsContent.kt @@ -54,8 +54,14 @@ fun PlaybackSettingsContent(player: Player) { SettingsHome( settings = settings, settingsClicked = { - navController.navigate(it.destination.route) { - launchSingleTop = true + val destination = it.destination + + if (destination is SettingsRoutes.MetricsOverlay) { + settingsViewModel.setMetricsOverlayEnabled(!destination.enabled) + } else { + navController.navigate(destination.route) { + launchSingleTop = true + } } }, ) diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/settings/AppSettingsView.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/settings/AppSettingsView.kt index c8a5afdaf..5332919e1 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/settings/AppSettingsView.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/settings/AppSettingsView.kt @@ -68,7 +68,7 @@ fun AppSettingsView( settingsViewModel: AppSettingsViewModel, modifier: Modifier = Modifier, ) { - val appSettings by settingsViewModel.currentAppSettings.collectAsStateWithLifecycle(AppSettings()) + val appSettings by settingsViewModel.currentAppSettings.collectAsStateWithLifecycle() Column( modifier = modifier