Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

436 remove error handling from playersurface #437

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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
Loading