diff --git a/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/AndroidPlayerSurfaceView.kt b/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/AndroidPlayerSurfaceView.kt deleted file mode 100644 index 17c5cc809..000000000 --- a/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/AndroidPlayerSurfaceView.kt +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) SRG SSR. All rights reserved. - * License information is available from the LICENSE file. - */ -package ch.srgssr.pillarbox.ui.widget.player - -import android.content.Context -import android.view.SurfaceView -import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.ui.Modifier -import androidx.compose.ui.draw.clipToBounds -import androidx.compose.ui.viewinterop.AndroidView -import androidx.media3.common.Player -import ch.srgssr.pillarbox.ui.extension.playerErrorAsState - -/** - * Render [player] content on a [SurfaceView] - * - * @param player The player to render on the SurfaceView. - * @param modifier The modifier to be applied to the layout. - */ -@Composable -fun AndroidPlayerSurfaceView(player: Player, modifier: Modifier = Modifier) { - val playerError by player.playerErrorAsState() - if (playerError != null) { - return - } - AndroidView( - /* - * On some devices (Pixel 2 XL Android 11) - * the "black" background of the SurfaceView shows outside its bound. - */ - modifier = modifier.clipToBounds(), - factory = { context -> - PlayerSurfaceView(context) - }, update = { view -> - view.player = player - }, onRelease = { view -> - view.player = null - }, onReset = { view -> - // onRested is called before update when composable is reuse with different context. - view.player = null - } - ) -} - -/** - * Player surface view - */ -internal class PlayerSurfaceView(context: Context) : SurfaceView(context) { - - /** - * Player if null is passed just clear surface - */ - var player: Player? = null - set(value) { - if (field != value) { - field?.clearVideoSurfaceView(this) - value?.setVideoSurfaceView(this) - } - field = value - } -} diff --git a/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/PlayerSurface.kt b/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/PlayerSurface.kt index aa2ed3279..23dc962bc 100644 --- a/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/PlayerSurface.kt +++ b/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/PlayerSurface.kt @@ -4,6 +4,8 @@ */ package ch.srgssr.pillarbox.ui.widget.player +import android.content.Context +import android.view.SurfaceView import androidx.compose.foundation.Canvas import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.BoxScope @@ -20,6 +22,7 @@ import androidx.compose.ui.draw.clipToBounds import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.drawscope.Stroke +import androidx.compose.ui.viewinterop.AndroidView import androidx.media3.common.Player import ch.srgssr.pillarbox.ui.ScaleMode import ch.srgssr.pillarbox.ui.exoplayer.ExoPlayerSubtitleView @@ -126,3 +129,48 @@ fun DebugPlayerView(modifier: Modifier) { ) } } + +/** + * Render the [player] content on a [SurfaceView]. + * + * @param player The player to render on the SurfaceView. + * @param modifier The modifier to be applied to the layout. + */ +@Composable +internal fun AndroidPlayerSurfaceView(player: Player, modifier: Modifier = Modifier) { + AndroidView( + /* + * On some devices (Pixel 2 XL Android 11) + * the "black" background of the SurfaceView shows outside its bound. + */ + modifier = modifier.clipToBounds(), + factory = { context -> + PlayerSurfaceView(context) + }, update = { view -> + view.player = player + }, onRelease = { view -> + view.player = null + }, onReset = { view -> + // onReset is called before `update`, when the composable is reused with a different context. + view.player = null + } + ) +} + +/** + * Player surface view + */ +internal class PlayerSurfaceView(context: Context) : SurfaceView(context) { + + /** + * Player if null is passed just clear surface + */ + var player: Player? = null + set(value) { + if (field != value) { + field?.clearVideoSurfaceView(this) + value?.setVideoSurfaceView(this) + } + field = value + } +} diff --git a/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/SphericalSurface.kt b/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/SphericalSurface.kt index f6dd81e0b..583c5fc80 100644 --- a/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/SphericalSurface.kt +++ b/pillarbox-ui/src/main/java/ch/srgssr/pillarbox/ui/widget/player/SphericalSurface.kt @@ -5,12 +5,10 @@ package ch.srgssr.pillarbox.ui.widget.player import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue import androidx.compose.ui.Modifier import androidx.compose.ui.viewinterop.AndroidView import androidx.media3.common.Player import androidx.media3.exoplayer.video.spherical.SphericalGLSurfaceView -import ch.srgssr.pillarbox.ui.extension.playerErrorAsState /** * Render the [player] content on a [SphericalGLSurfaceView]. @@ -20,10 +18,6 @@ import ch.srgssr.pillarbox.ui.extension.playerErrorAsState */ @Composable fun SphericalSurface(player: Player, modifier: Modifier = Modifier) { - val playerError by player.playerErrorAsState() - if (playerError != null) { - return - } AndroidView( modifier = modifier, factory = { context ->