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.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()) {
|
||||||
com.huanchengfly.tieba.post.ui.widgets.compose.VideoPlayer(
|
Box(
|
||||||
videoUrl = videoUrl,
|
modifier = Modifier.clickable(
|
||||||
thumbnailUrl = picUrl,
|
interactionSource = remember { MutableInteractionSource() },
|
||||||
modifier = picModifier
|
indication = null,
|
||||||
)
|
onClick = {}
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
com.huanchengfly.tieba.post.ui.widgets.compose.VideoPlayer(
|
||||||
|
videoUrl = videoUrl,
|
||||||
|
thumbnailUrl = picUrl,
|
||||||
|
modifier = picModifier
|
||||||
|
)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
AsyncImage(
|
AsyncImage(
|
||||||
imageUri = picUrl,
|
imageUri = picUrl,
|
||||||
|
|
|
||||||
|
|
@ -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,14 +357,22 @@ private fun ThreadMedia(
|
||||||
16f / 9
|
16f / 9
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
VideoPlayer(
|
Box(
|
||||||
videoUrl = videoInfo.get { videoUrl },
|
modifier = Modifier.clickable(
|
||||||
thumbnailUrl = videoInfo.get { thumbnailUrl },
|
interactionSource = remember { MutableInteractionSource() },
|
||||||
modifier = Modifier
|
indication = null,
|
||||||
.fillMaxWidth(singleMediaFraction)
|
onClick = {}
|
||||||
.aspectRatio(aspectRatio)
|
)
|
||||||
.clip(RoundedCornerShape(8.dp))
|
) {
|
||||||
)
|
VideoPlayer(
|
||||||
|
videoUrl = videoInfo.get { videoUrl },
|
||||||
|
thumbnailUrl = videoInfo.get { thumbnailUrl },
|
||||||
|
modifier = Modifier
|
||||||
|
.fillMaxWidth(singleMediaFraction)
|
||||||
|
.aspectRatio(aspectRatio)
|
||||||
|
.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 ->
|
||||||
|
|
|
||||||
|
|
@ -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() }
|
||||||
|
) {}
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -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 {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue