do not autoplay videos when on mobile data
This commit is contained in:
@@ -179,8 +179,11 @@ fun ImageVideoPost(postViewModel: NewMediaModel, acc: Account) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
val showVideo = remember {
|
||||||
|
mutableStateOf(true)
|
||||||
|
}
|
||||||
postViewModel.galleryUri?.let {
|
postViewModel.galleryUri?.let {
|
||||||
VideoView(it.toString())
|
VideoView(it.toString(), showVideo = showVideo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -330,7 +330,7 @@ fun NewPostView(onClose: () -> Unit, baseReplyTo: Note? = null, quote: Note? = n
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
} else if (videoExtensions.any { removedParamsFromUrl.endsWith(it) }) {
|
||||||
VideoView(myUrlPreview)
|
VideoView(myUrlPreview, showVideo = remember { mutableStateOf(true) })
|
||||||
} else {
|
} else {
|
||||||
UrlPreview(myUrlPreview, myUrlPreview)
|
UrlPreview(myUrlPreview, myUrlPreview)
|
||||||
}
|
}
|
||||||
@@ -966,7 +966,7 @@ fun ImageVideoDescription(
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
VideoView(uri.toString())
|
VideoView(uri.toString(), showVideo = remember { mutableStateOf(true) })
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import androidx.compose.material.icons.filled.VolumeUp
|
|||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.runtime.DisposableEffect
|
import androidx.compose.runtime.DisposableEffect
|
||||||
import androidx.compose.runtime.LaunchedEffect
|
import androidx.compose.runtime.LaunchedEffect
|
||||||
|
import androidx.compose.runtime.MutableState
|
||||||
import androidx.compose.runtime.Stable
|
import androidx.compose.runtime.Stable
|
||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
@@ -68,7 +69,13 @@ import kotlin.time.measureTimedValue
|
|||||||
public var DefaultMutedSetting = mutableStateOf(true)
|
public var DefaultMutedSetting = mutableStateOf(true)
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun LoadThumbAndThenVideoView(videoUri: String, description: String? = null, thumbUri: String, onDialog: ((Boolean) -> Unit)? = null) {
|
fun LoadThumbAndThenVideoView(
|
||||||
|
videoUri: String,
|
||||||
|
description: String? = null,
|
||||||
|
thumbUri: String,
|
||||||
|
showVideo: MutableState<Boolean>,
|
||||||
|
onDialog: ((Boolean) -> Unit)? = null
|
||||||
|
) {
|
||||||
var loadingFinished by remember { mutableStateOf<Pair<Boolean, Drawable?>>(Pair(false, null)) }
|
var loadingFinished by remember { mutableStateOf<Pair<Boolean, Drawable?>>(Pair(false, null)) }
|
||||||
|
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@@ -92,9 +99,9 @@ fun LoadThumbAndThenVideoView(videoUri: String, description: String? = null, thu
|
|||||||
|
|
||||||
if (loadingFinished.first) {
|
if (loadingFinished.first) {
|
||||||
if (loadingFinished.second != null) {
|
if (loadingFinished.second != null) {
|
||||||
VideoView(videoUri, description, VideoThumb(loadingFinished.second), onDialog)
|
VideoView(videoUri, description, VideoThumb(loadingFinished.second), showVideo, onDialog)
|
||||||
} else {
|
} else {
|
||||||
VideoView(videoUri, description, null, onDialog)
|
VideoView(videoUri, description, null, showVideo, onDialog)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -105,10 +112,11 @@ fun VideoView(
|
|||||||
videoUri: String,
|
videoUri: String,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
thumb: VideoThumb? = null,
|
thumb: VideoThumb? = null,
|
||||||
|
showVideo: MutableState<Boolean>,
|
||||||
onDialog: ((Boolean) -> Unit)? = null
|
onDialog: ((Boolean) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
val (value, elapsed) = measureTimedValue {
|
val (value, elapsed) = measureTimedValue {
|
||||||
VideoView1(videoUri, description, thumb, onDialog)
|
VideoView1(videoUri, description, thumb, onDialog, showVideo)
|
||||||
}
|
}
|
||||||
Log.d("Rendering Metrics", "VideoView $elapsed $videoUri")
|
Log.d("Rendering Metrics", "VideoView $elapsed $videoUri")
|
||||||
}
|
}
|
||||||
@@ -118,7 +126,8 @@ fun VideoView1(
|
|||||||
videoUri: String,
|
videoUri: String,
|
||||||
description: String? = null,
|
description: String? = null,
|
||||||
thumb: VideoThumb? = null,
|
thumb: VideoThumb? = null,
|
||||||
onDialog: ((Boolean) -> Unit)? = null
|
onDialog: ((Boolean) -> Unit)? = null,
|
||||||
|
showVideo: MutableState<Boolean>
|
||||||
) {
|
) {
|
||||||
var exoPlayerData by remember { mutableStateOf<VideoPlayer?>(null) }
|
var exoPlayerData by remember { mutableStateOf<VideoPlayer?>(null) }
|
||||||
val defaultToStart by remember { mutableStateOf(DefaultMutedSetting.value) }
|
val defaultToStart by remember { mutableStateOf(DefaultMutedSetting.value) }
|
||||||
@@ -133,7 +142,7 @@ fun VideoView1(
|
|||||||
}
|
}
|
||||||
|
|
||||||
exoPlayerData?.let {
|
exoPlayerData?.let {
|
||||||
VideoView(videoUri, description, it, defaultToStart, thumb, onDialog)
|
VideoView(videoUri, description, it, defaultToStart, thumb, onDialog, showVideo = showVideo)
|
||||||
}
|
}
|
||||||
|
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
@@ -151,10 +160,11 @@ fun VideoView(
|
|||||||
exoPlayerData: VideoPlayer,
|
exoPlayerData: VideoPlayer,
|
||||||
defaultToStart: Boolean = false,
|
defaultToStart: Boolean = false,
|
||||||
thumb: VideoThumb? = null,
|
thumb: VideoThumb? = null,
|
||||||
onDialog: ((Boolean) -> Unit)? = null
|
onDialog: ((Boolean) -> Unit)? = null,
|
||||||
|
showVideo: MutableState<Boolean>
|
||||||
) {
|
) {
|
||||||
val (value, elapsed) = measureTimedValue {
|
val (value, elapsed) = measureTimedValue {
|
||||||
VideoView1(videoUri, description, exoPlayerData, defaultToStart, thumb, onDialog)
|
VideoView1(videoUri, description, exoPlayerData, defaultToStart, thumb, onDialog, showVideo)
|
||||||
}
|
}
|
||||||
Log.d("Rendering Metrics", "VideoView $elapsed $videoUri")
|
Log.d("Rendering Metrics", "VideoView $elapsed $videoUri")
|
||||||
}
|
}
|
||||||
@@ -166,7 +176,8 @@ fun VideoView1(
|
|||||||
exoPlayerData: VideoPlayer,
|
exoPlayerData: VideoPlayer,
|
||||||
defaultToStart: Boolean = false,
|
defaultToStart: Boolean = false,
|
||||||
thumb: VideoThumb? = null,
|
thumb: VideoThumb? = null,
|
||||||
onDialog: ((Boolean) -> Unit)? = null
|
onDialog: ((Boolean) -> Unit)? = null,
|
||||||
|
showVideo: MutableState<Boolean>
|
||||||
) {
|
) {
|
||||||
val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current)
|
val lifecycleOwner = rememberUpdatedState(LocalLifecycleOwner.current)
|
||||||
|
|
||||||
@@ -196,7 +207,7 @@ fun VideoView1(
|
|||||||
prepare()
|
prepare()
|
||||||
}
|
}
|
||||||
|
|
||||||
RenderVideoPlayer(exoPlayerData, thumb, onDialog)
|
RenderVideoPlayer(exoPlayerData, thumb, showVideo, onDialog)
|
||||||
|
|
||||||
DisposableEffect(Unit) {
|
DisposableEffect(Unit) {
|
||||||
val observer = LifecycleEventObserver { _, event ->
|
val observer = LifecycleEventObserver { _, event ->
|
||||||
@@ -230,6 +241,7 @@ data class VideoThumb(
|
|||||||
private fun RenderVideoPlayer(
|
private fun RenderVideoPlayer(
|
||||||
playerData: VideoPlayer,
|
playerData: VideoPlayer,
|
||||||
thumbData: VideoThumb?,
|
thumbData: VideoThumb?,
|
||||||
|
showVideo: MutableState<Boolean>,
|
||||||
onDialog: ((Boolean) -> Unit)?
|
onDialog: ((Boolean) -> Unit)?
|
||||||
) {
|
) {
|
||||||
val context = LocalContext.current
|
val context = LocalContext.current
|
||||||
@@ -241,7 +253,9 @@ private fun RenderVideoPlayer(
|
|||||||
.defaultMinSize(minHeight = 70.dp)
|
.defaultMinSize(minHeight = 70.dp)
|
||||||
.align(Alignment.Center)
|
.align(Alignment.Center)
|
||||||
.onVisibilityChanges { visible ->
|
.onVisibilityChanges { visible ->
|
||||||
if (visible && !playerData.exoPlayer.isPlaying) {
|
if (!showVideo.value && visible && !playerData.exoPlayer.isPlaying) {
|
||||||
|
playerData.exoPlayer.pause()
|
||||||
|
} else if (visible && !playerData.exoPlayer.isPlaying) {
|
||||||
playerData.exoPlayer.play()
|
playerData.exoPlayer.play()
|
||||||
} else if (!visible && playerData.exoPlayer.isPlaying) {
|
} else if (!visible && playerData.exoPlayer.isPlaying) {
|
||||||
playerData.exoPlayer.pause()
|
playerData.exoPlayer.pause()
|
||||||
|
|||||||
@@ -204,11 +204,11 @@ fun ZoomableContentView(content: ZoomableContent, images: ImmutableList<Zoomable
|
|||||||
|
|
||||||
when (content) {
|
when (content) {
|
||||||
is ZoomableUrlImage -> UrlImageView(content, mainImageModifier, showImage)
|
is ZoomableUrlImage -> UrlImageView(content, mainImageModifier, showImage)
|
||||||
is ZoomableUrlVideo -> VideoView(content.url, content.description) { dialogOpen = true }
|
is ZoomableUrlVideo -> VideoView(content.url, content.description, showVideo = showImage) { dialogOpen = true }
|
||||||
is ZoomableLocalImage -> LocalImageView(content, mainImageModifier)
|
is ZoomableLocalImage -> LocalImageView(content, mainImageModifier)
|
||||||
is ZoomableLocalVideo ->
|
is ZoomableLocalVideo ->
|
||||||
content.localFile?.let {
|
content.localFile?.let {
|
||||||
VideoView(it.toUri().toString(), content.description) { dialogOpen = true }
|
VideoView(it.toUri().toString(), content.description, showVideo = showImage) { dialogOpen = true }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,14 +578,14 @@ fun RenderImageOrVideo(content: ZoomableContent) {
|
|||||||
UrlImageView(content = content, mainImageModifier = mainModifier, showImage)
|
UrlImageView(content = content, mainImageModifier = mainModifier, showImage)
|
||||||
} else if (content is ZoomableUrlVideo) {
|
} else if (content is ZoomableUrlVideo) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
|
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
|
||||||
VideoView(content.url, content.description)
|
VideoView(content.url, content.description, showVideo = showImage)
|
||||||
}
|
}
|
||||||
} else if (content is ZoomableLocalImage) {
|
} else if (content is ZoomableLocalImage) {
|
||||||
LocalImageView(content = content, mainImageModifier = mainModifier)
|
LocalImageView(content = content, mainImageModifier = mainModifier)
|
||||||
} else if (content is ZoomableLocalVideo) {
|
} else if (content is ZoomableLocalVideo) {
|
||||||
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
|
Row(verticalAlignment = Alignment.CenterVertically, modifier = Modifier.fillMaxSize(1f)) {
|
||||||
content.localFile?.let {
|
content.localFile?.let {
|
||||||
VideoView(it.toUri().toString(), content.description)
|
VideoView(it.toUri().toString(), content.description, showVideo = showImage)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3043,12 +3043,14 @@ fun AudioTrackHeader(noteEvent: AudioTrackEvent, accountViewModel: AccountViewMo
|
|||||||
LoadThumbAndThenVideoView(
|
LoadThumbAndThenVideoView(
|
||||||
videoUri = media,
|
videoUri = media,
|
||||||
description = noteEvent.subject(),
|
description = noteEvent.subject(),
|
||||||
thumbUri = cover
|
thumbUri = cover,
|
||||||
|
showVideo = remember { mutableStateOf(true) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
?: VideoView(
|
?: VideoView(
|
||||||
videoUri = media,
|
videoUri = media,
|
||||||
noteEvent.subject()
|
description = noteEvent.subject(),
|
||||||
|
showVideo = remember { mutableStateOf(true) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -3172,7 +3174,8 @@ fun RenderLiveActivityEventInner(baseNote: Note, accountViewModel: AccountViewMo
|
|||||||
) {
|
) {
|
||||||
VideoView(
|
VideoView(
|
||||||
videoUri = media,
|
videoUri = media,
|
||||||
description = subject
|
description = subject,
|
||||||
|
showVideo = remember { mutableStateOf(true) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user