fix: 视频播放器重建后自动播放
This commit is contained in:
parent
1137f0eead
commit
936aa4d2cf
|
|
@ -4,6 +4,8 @@ import androidx.compose.foundation.clickable
|
|||
import androidx.compose.foundation.gestures.awaitEachGesture
|
||||
import androidx.compose.foundation.gestures.awaitFirstDown
|
||||
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.fillMaxWidth
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
|
|
@ -188,11 +190,19 @@ data class VideoContentRender(
|
|||
.aspectRatio(width * 1f / height)
|
||||
|
||||
if (videoUrl.isNotBlank()) {
|
||||
com.huanchengfly.tieba.post.ui.widgets.compose.VideoPlayer(
|
||||
videoUrl = videoUrl,
|
||||
thumbnailUrl = picUrl,
|
||||
modifier = picModifier
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = null,
|
||||
onClick = {}
|
||||
)
|
||||
) {
|
||||
com.huanchengfly.tieba.post.ui.widgets.compose.VideoPlayer(
|
||||
videoUrl = videoUrl,
|
||||
thumbnailUrl = picUrl,
|
||||
modifier = picModifier
|
||||
)
|
||||
}
|
||||
} else {
|
||||
AsyncImage(
|
||||
imageUri = picUrl,
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import android.util.Log
|
|||
import androidx.compose.animation.animateColorAsState
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.clickable
|
||||
import androidx.compose.foundation.interaction.MutableInteractionSource
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
|
|
@ -356,14 +357,22 @@ private fun ThreadMedia(
|
|||
16f / 9
|
||||
)
|
||||
}
|
||||
VideoPlayer(
|
||||
videoUrl = videoInfo.get { videoUrl },
|
||||
thumbnailUrl = videoInfo.get { thumbnailUrl },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(singleMediaFraction)
|
||||
.aspectRatio(aspectRatio)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier.clickable(
|
||||
interactionSource = remember { MutableInteractionSource() },
|
||||
indication = null,
|
||||
onClick = {}
|
||||
)
|
||||
) {
|
||||
VideoPlayer(
|
||||
videoUrl = videoInfo.get { videoUrl },
|
||||
thumbnailUrl = videoInfo.get { thumbnailUrl },
|
||||
modifier = Modifier
|
||||
.fillMaxWidth(singleMediaFraction)
|
||||
.aspectRatio(aspectRatio)
|
||||
.clip(RoundedCornerShape(8.dp))
|
||||
)
|
||||
}
|
||||
} else if (hasMedia) {
|
||||
val mediaWidthFraction = remember(isSingleMedia, singleMediaFraction) {
|
||||
if (isSingleMedia) singleMediaFraction else 1f
|
||||
|
|
@ -646,11 +655,12 @@ fun VideoPlayer(
|
|||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||
} else {
|
||||
context.findActivity()?.requestedOrientation =
|
||||
ActivityInfo.SCREEN_ORIENTATION_USER_PORTRAIT
|
||||
ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
}
|
||||
}
|
||||
}
|
||||
)
|
||||
|
||||
val fullScreen by (videoPlayerController as DefaultVideoPlayerController).collect { isFullScreen }
|
||||
val videoPlayerContent =
|
||||
movableContentOf { isFullScreen: Boolean, playerModifier: Modifier ->
|
||||
|
|
|
|||
|
|
@ -63,6 +63,16 @@ fun MediaControlButtons(
|
|||
.background(Color.Black.copy(alpha = appearAlpha.value * 0.6f))
|
||||
.then(modifier)
|
||||
)
|
||||
} else {
|
||||
Box(modifier = modifier) {
|
||||
Box(modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.clickable(
|
||||
indication = null,
|
||||
interactionSource = remember { MutableInteractionSource() }
|
||||
) {}
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ fun rememberVideoPlayerController(
|
|||
override fun restore(value: VideoPlayerState): DefaultVideoPlayerController {
|
||||
return DefaultVideoPlayerController(
|
||||
context = context,
|
||||
initialState = value,
|
||||
initialState = value.copy(isPlaying = playWhenReady),
|
||||
coroutineScope = coroutineScope,
|
||||
fullScreenModeChangedListener = fullScreenModeChangedListener
|
||||
).apply {
|
||||
|
|
|
|||
Loading…
Reference in New Issue