Skip to content

Commit

Permalink
restructure PlaySurface
Browse files Browse the repository at this point in the history
  • Loading branch information
theScrabi committed Nov 1, 2024
1 parent c392897 commit 73ad522
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@

package net.newpipe.newplayer.ui.videoplayer

import android.app.Activity
import android.view.SurfaceView
import androidx.annotation.OptIn
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio
Expand All @@ -30,21 +32,36 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.viewinterop.AndroidView
import androidx.lifecycle.Lifecycle
import androidx.media3.common.Player
import androidx.media3.common.util.UnstableApi
import net.newpipe.newplayer.ui.ContentScale
import net.newpipe.newplayer.uiModel.NewPlayerUIState

/** @hide */
@OptIn(UnstableApi::class)
@Composable
internal fun PlaySurface(
modifier: Modifier,
player: Player?,
lifecycle: Lifecycle.Event,
fitMode: ContentScale,
uiRatio: Float,
contentRatio: Float
uiState: NewPlayerUIState
) {

val activity = LocalContext.current as Activity

val displayMetrics = activity.resources.displayMetrics

val screenRatio =
displayMetrics.widthPixels.toFloat() / displayMetrics.heightPixels.toFloat()

val fitMode = uiState.contentFitMode
val uiRatio = if (uiState.uiMode.fullscreen) screenRatio
else uiState.embeddedUiRatio
val contentRatio = uiState.contentRatio

val internalModifier = modifier.aspectRatio(contentRatio)

if (uiRatio <= contentRatio) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ internal fun VideoPlayerUi(viewModel: InternalNewPlayerViewModel, uiState: NewPl

val activity = LocalContext.current as Activity

val displayMetrics = activity.resources.displayMetrics

val screenRatio =
displayMetrics.widthPixels.toFloat() / displayMetrics.heightPixels.toFloat()

val lifecycleOwner = androidx.lifecycle.compose.LocalLifecycleOwner.current

var videoViewBounds by remember {
Expand Down Expand Up @@ -137,10 +132,7 @@ internal fun VideoPlayerUi(viewModel: InternalNewPlayerViewModel, uiState: NewPl
},
player = exoPlayer,
lifecycle = lifecycle,
fitMode = uiState.contentFitMode,
uiRatio = if (uiState.uiMode.fullscreen) screenRatio
else uiState.embeddedUiRatio,
contentRatio = uiState.contentRatio,
uiState = uiState
)
}
}
Expand Down

0 comments on commit 73ad522

Please sign in to comment.