diff --git a/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/SRGErrorMessageProvider.kt b/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/SRGErrorMessageProvider.kt index e4af70681..dea5adaeb 100644 --- a/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/SRGErrorMessageProvider.kt +++ b/pillarbox-core-business/src/main/java/ch/srgssr/pillarbox/core/business/SRGErrorMessageProvider.kt @@ -4,6 +4,7 @@ */ package ch.srgssr.pillarbox.core.business +import android.content.Context import android.os.RemoteException import android.util.Pair import androidx.media3.common.ErrorMessageProvider @@ -11,16 +12,18 @@ import androidx.media3.common.PlaybackException import ch.srgssr.pillarbox.core.business.integrationlayer.data.BlockReasonException import ch.srgssr.pillarbox.core.business.integrationlayer.data.ResourceNotFoundException import io.ktor.client.plugins.ClientRequestException +import kotlinx.serialization.SerializationException /** * Process error message from [PlaybackException] */ -class SRGErrorMessageProvider : ErrorMessageProvider { +class SRGErrorMessageProvider(private val context: Context) : ErrorMessageProvider { override fun getErrorMessage(throwable: PlaybackException): Pair { return when (val cause = throwable.cause) { is BlockReasonException -> { - Pair.create(0, cause.blockReason.name) + val message = context.resources.getStringArray(R.array.blockReasonArray)[cause.blockReason.ordinal] + Pair.create(0, message) } // When using MediaController, RemoteException is send instead of HttpException. is RemoteException -> @@ -31,11 +34,15 @@ class SRGErrorMessageProvider : ErrorMessageProvider { } is ResourceNotFoundException -> { - Pair.create(0, "Can't find Resource to play") + Pair.create(0, context.getString(R.string.noPlayableResourceFound)) + } + + is SerializationException -> { + Pair.create(0, context.getString(R.string.invalidDataError)) } else -> { - Pair.create(throwable.errorCode, "${throwable.localizedMessage} (${throwable.errorCodeName})") + Pair.create(throwable.errorCode, context.getString(R.string.unkownError)) } } } diff --git a/pillarbox-core-business/src/main/res/values-de/strings.xml b/pillarbox-core-business/src/main/res/values-de/strings.xml new file mode 100644 index 000000000..620589ba1 --- /dev/null +++ b/pillarbox-core-business/src/main/res/values-de/strings.xml @@ -0,0 +1,15 @@ + + + The data is invalid + Dieser Inhalt ist ausserhalb der Schweiz nicht verfügbar. + Dieser Inhalt ist aus rechtlichen Gründen nicht verfügbar. + Dieser Werbe-Inhalt ist nicht verfügbar. + Dieser Inhalt ist aus Gründen des Jugendschutzes nur zwischen 22:00 und 5:00 Uhr verfügbar. + Dieser Inhalt ist aus Gründen des Jugendschutzes nur zwischen 20:00 und 6:00 Uhr verfügbar. + Dieser Inhalt ist noch nicht verfügbar. + Dieser Inhalt ist nicht mehr verfügbar. + Dieser Inhalt ist nicht verfügbar. + diff --git a/pillarbox-core-business/src/main/res/values-fr/strings.xml b/pillarbox-core-business/src/main/res/values-fr/strings.xml new file mode 100644 index 000000000..05f9bfef7 --- /dev/null +++ b/pillarbox-core-business/src/main/res/values-fr/strings.xml @@ -0,0 +1,17 @@ + + + Les données sont invalides. + Aucune ressource jouable n\'a pu être trouvée. + Ce contenu n\'est pas disponible hors de Suisse. + Ce contenu a été retiré par décision de justice. + Ce contenu n’est actuellement pas disponible. + Ce contenu n\'est disponible qu\'entre 22h et 5h afin de protéger le jeune public. + Ce contenu n\'est disponible qu\'entre 20h et 6h afin de protéger le jeune public. + Ce contenu n’est pas encore disponible. + Ce contenu n’est plus disponible. + Ce contenu n’est pas disponible. + Erreur inconnue + diff --git a/pillarbox-core-business/src/main/res/values-it/strings.xml b/pillarbox-core-business/src/main/res/values-it/strings.xml new file mode 100644 index 000000000..648b5afa3 --- /dev/null +++ b/pillarbox-core-business/src/main/res/values-it/strings.xml @@ -0,0 +1,13 @@ + + + The data is invalid + Questo media non è disponibile fuori dalla Svizzera. + Questo media non è disponibile a causa di restrizioni legali. + Questo contenuto commerciale non è disponibile. + Questo media non è ancora disponibile. + Questo media non è più disponibile. + Questo media non è disponibile. + diff --git a/pillarbox-core-business/src/main/res/values-rm/strings.xml b/pillarbox-core-business/src/main/res/values-rm/strings.xml new file mode 100644 index 000000000..383357a1f --- /dev/null +++ b/pillarbox-core-business/src/main/res/values-rm/strings.xml @@ -0,0 +1,13 @@ + + + The data is invalid + Quest medium n\'è betg disponibel ordaifer la Svizra. + Quest medium n\'è betg disponibel perquei ch\'el è scadì. + Quest medium commerzial n\'è betg disponibel. + Quest medium n\'è betg anc disponibel. + Quest medium n\'è betg pli disponibel. + Quest medium n\'è betg disponibel. + diff --git a/pillarbox-core-business/src/main/res/values/string.xml b/pillarbox-core-business/src/main/res/values/string.xml new file mode 100644 index 000000000..7eb3a15bb --- /dev/null +++ b/pillarbox-core-business/src/main/res/values/string.xml @@ -0,0 +1,29 @@ + + + Unknown error + The data is invalid + No playable resources could be found. + This content is not available outside Switzerland. + This content is not available due to legal restrictions. + This commercial content is not available. + To protect children this content is only available between 10PM and 5AM. + To protect children this content is only available between 8PM and 6AM. + This content is not available yet. + This content is not available anymore. + This content is not available. + + + + @string/blockReason_geoBlock + @string/blockReason_legal + @string/blockReason_commercial + @string/blockReason_ageRating18 + @string/blockReason_ageRating12 + @string/blockReason_startDate + @string/blockReason_endDate + @string/blockReason_unknown + + diff --git a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/controls/PlayerError.kt b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/controls/PlayerError.kt index 3cedcdcb9..f26a31e6c 100644 --- a/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/controls/PlayerError.kt +++ b/pillarbox-demo/src/main/java/ch/srgssr/pillarbox/demo/ui/player/controls/PlayerError.kt @@ -15,6 +15,7 @@ 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.media3.common.PlaybackException import ch.srgssr.pillarbox.core.business.SRGErrorMessageProvider @@ -29,8 +30,9 @@ import ch.srgssr.pillarbox.core.business.SRGErrorMessageProvider */ @Composable fun PlayerError(playerError: PlaybackException, modifier: Modifier = Modifier, onRetry: () -> Unit) { - val errorMessageProvider = remember { - SRGErrorMessageProvider() + val context = LocalContext.current + val errorMessageProvider = remember(context) { + SRGErrorMessageProvider(context) } Surface(modifier, color = Color.Black) { Box(