-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add simple error to the player on tv
- Loading branch information
Showing
2 changed files
with
105 additions
and
33 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
pillarbox-demo-tv/src/main/java/ch/srgssr/pillarbox/demo/tv/player/compose/ErrorView.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (c) SRG SSR. All rights reserved. | ||
* License information is available from the LICENSE file. | ||
*/ | ||
package ch.srgssr.pillarbox.demo.tv.player.compose | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.text.font.FontStyle | ||
import androidx.compose.ui.tooling.preview.Preview | ||
import androidx.media3.common.PlaybackException | ||
import androidx.tv.material3.ExperimentalTvMaterial3Api | ||
import androidx.tv.material3.Text | ||
import ch.srgssr.pillarbox.core.business.SRGErrorMessageProvider | ||
|
||
/** | ||
* Player error | ||
* | ||
* @param playerError The player error. | ||
* @param modifier The modifier to layout the view. | ||
* @param onRetry Action to retry. | ||
* @receiver | ||
*/ | ||
@OptIn(ExperimentalTvMaterial3Api::class) | ||
@Composable | ||
fun PlayerError(playerError: PlaybackException, modifier: Modifier = Modifier, onRetry: () -> Unit) { | ||
val context = LocalContext.current | ||
val errorMessageProvider = remember(context) { | ||
SRGErrorMessageProvider(context) | ||
} | ||
Box( | ||
modifier = Modifier | ||
.fillMaxSize() | ||
.clickable { onRetry.invoke() } | ||
) { | ||
Column(modifier = Modifier.align(Alignment.Center), horizontalAlignment = Alignment.CenterHorizontally) { | ||
Text( | ||
text = errorMessageProvider.getErrorMessage(playerError).second, | ||
color = Color.White | ||
) | ||
Text(text = "Click to retry!", color = Color.LightGray, fontStyle = FontStyle.Italic) | ||
} | ||
} | ||
} | ||
|
||
@Preview | ||
@Composable | ||
private fun PlayerErrorPreview() { | ||
PlayerError(playerError = PlaybackException("", null, PlaybackException.ERROR_CODE_UNSPECIFIED)) { | ||
// Nothing | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters