Skip to content

Commit

Permalink
436 remove error handling from playersurface (#437)
Browse files Browse the repository at this point in the history
Co-authored-by: Gaëtan Muller <[email protected]>
  • Loading branch information
StaehliJ and MGaetan89 authored Feb 5, 2024
1 parent d1f8ac3 commit bcce330
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 70 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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].
Expand All @@ -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 ->
Expand Down

0 comments on commit bcce330

Please sign in to comment.