fix: 视频播放器重建后自动播放

This commit is contained in:
HuanCheng65 2023-09-30 16:28:04 +08:00
parent 1137f0eead
commit 936aa4d2cf
No known key found for this signature in database
GPG Key ID: 5EC9DD60A32C7360
4 changed files with 45 additions and 15 deletions

View File

@ -4,6 +4,8 @@ import androidx.compose.foundation.clickable
import androidx.compose.foundation.gestures.awaitEachGesture import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.awaitFirstDown import androidx.compose.foundation.gestures.awaitFirstDown
import androidx.compose.foundation.gestures.waitForUpOrCancellation import androidx.compose.foundation.gestures.waitForUpOrCancellation
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.aspectRatio import androidx.compose.foundation.layout.aspectRatio
import androidx.compose.foundation.layout.fillMaxWidth import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
@ -188,11 +190,19 @@ data class VideoContentRender(
.aspectRatio(width * 1f / height) .aspectRatio(width * 1f / height)
if (videoUrl.isNotBlank()) { if (videoUrl.isNotBlank()) {
Box(
modifier = Modifier.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = {}
)
) {
com.huanchengfly.tieba.post.ui.widgets.compose.VideoPlayer( com.huanchengfly.tieba.post.ui.widgets.compose.VideoPlayer(
videoUrl = videoUrl, videoUrl = videoUrl,
thumbnailUrl = picUrl, thumbnailUrl = picUrl,
modifier = picModifier modifier = picModifier
) )
}
} else { } else {
AsyncImage( AsyncImage(
imageUri = picUrl, imageUri = picUrl,

View File

@ -5,6 +5,7 @@ import android.util.Log
import androidx.compose.animation.animateColorAsState import androidx.compose.animation.animateColorAsState
import androidx.compose.foundation.background import androidx.compose.foundation.background
import androidx.compose.foundation.clickable import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Box import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Column
@ -356,6 +357,13 @@ private fun ThreadMedia(
16f / 9 16f / 9
) )
} }
Box(
modifier = Modifier.clickable(
interactionSource = remember { MutableInteractionSource() },
indication = null,
onClick = {}
)
) {
VideoPlayer( VideoPlayer(
videoUrl = videoInfo.get { videoUrl }, videoUrl = videoInfo.get { videoUrl },
thumbnailUrl = videoInfo.get { thumbnailUrl }, thumbnailUrl = videoInfo.get { thumbnailUrl },
@ -364,6 +372,7 @@ private fun ThreadMedia(
.aspectRatio(aspectRatio) .aspectRatio(aspectRatio)
.clip(RoundedCornerShape(8.dp)) .clip(RoundedCornerShape(8.dp))
) )
}
} else if (hasMedia) { } else if (hasMedia) {
val mediaWidthFraction = remember(isSingleMedia, singleMediaFraction) { val mediaWidthFraction = remember(isSingleMedia, singleMediaFraction) {
if (isSingleMedia) singleMediaFraction else 1f if (isSingleMedia) singleMediaFraction else 1f
@ -646,11 +655,12 @@ fun VideoPlayer(
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
} else { } else {
context.findActivity()?.requestedOrientation = context.findActivity()?.requestedOrientation =
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
} }
} }
} }
) )
val fullScreen by (videoPlayerController as DefaultVideoPlayerController).collect { isFullScreen } val fullScreen by (videoPlayerController as DefaultVideoPlayerController).collect { isFullScreen }
val videoPlayerContent = val videoPlayerContent =
movableContentOf { isFullScreen: Boolean, playerModifier: Modifier -> movableContentOf { isFullScreen: Boolean, playerModifier: Modifier ->

View File

@ -63,6 +63,16 @@ fun MediaControlButtons(
.background(Color.Black.copy(alpha = appearAlpha.value * 0.6f)) .background(Color.Black.copy(alpha = appearAlpha.value * 0.6f))
.then(modifier) .then(modifier)
) )
} else {
Box(modifier = modifier) {
Box(modifier = Modifier
.fillMaxSize()
.clickable(
indication = null,
interactionSource = remember { MutableInteractionSource() }
) {}
)
}
} }
} }

View File

@ -70,7 +70,7 @@ fun rememberVideoPlayerController(
override fun restore(value: VideoPlayerState): DefaultVideoPlayerController { override fun restore(value: VideoPlayerState): DefaultVideoPlayerController {
return DefaultVideoPlayerController( return DefaultVideoPlayerController(
context = context, context = context,
initialState = value, initialState = value.copy(isPlaying = playWhenReady),
coroutineScope = coroutineScope, coroutineScope = coroutineScope,
fullScreenModeChangedListener = fullScreenModeChangedListener fullScreenModeChangedListener = fullScreenModeChangedListener
).apply { ).apply {