Moves the creation of the MediaItem to a thread.
This commit is contained in:
@@ -37,6 +37,7 @@ import androidx.compose.runtime.derivedStateOf
|
|||||||
import androidx.compose.runtime.getValue
|
import androidx.compose.runtime.getValue
|
||||||
import androidx.compose.runtime.mutableIntStateOf
|
import androidx.compose.runtime.mutableIntStateOf
|
||||||
import androidx.compose.runtime.mutableStateOf
|
import androidx.compose.runtime.mutableStateOf
|
||||||
|
import androidx.compose.runtime.produceState
|
||||||
import androidx.compose.runtime.remember
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.runtime.rememberCoroutineScope
|
import androidx.compose.runtime.rememberCoroutineScope
|
||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
@@ -223,7 +224,12 @@ fun VideoView(
|
|||||||
|
|
||||||
Box(modifier, contentAlignment = Alignment.Center) {
|
Box(modifier, contentAlignment = Alignment.Center) {
|
||||||
if (!automaticallyStartPlayback.value) {
|
if (!automaticallyStartPlayback.value) {
|
||||||
DisplayBlurHash(blurhash, null, ContentScale.Crop, MaterialTheme.colorScheme.imageModifier)
|
DisplayBlurHash(
|
||||||
|
blurhash,
|
||||||
|
null,
|
||||||
|
ContentScale.Crop,
|
||||||
|
MaterialTheme.colorScheme.imageModifier
|
||||||
|
)
|
||||||
IconButton(
|
IconButton(
|
||||||
modifier = Modifier.size(Size75dp),
|
modifier = Modifier.size(Size75dp),
|
||||||
onClick = { automaticallyStartPlayback.value = true }
|
onClick = { automaticallyStartPlayback.value = true }
|
||||||
@@ -273,32 +279,7 @@ fun VideoViewInner(
|
|||||||
onDialog: ((Boolean) -> Unit)? = null
|
onDialog: ((Boolean) -> Unit)? = null
|
||||||
) {
|
) {
|
||||||
VideoPlayerActiveMutex(videoUri) { modifier, activeOnScreen ->
|
VideoPlayerActiveMutex(videoUri) { modifier, activeOnScreen ->
|
||||||
val mediaItem = remember(videoUri) {
|
GetMediaItem(videoUri, title, artworkUri, authorName) { mediaItem ->
|
||||||
mutableStateOf(
|
|
||||||
MediaItem.Builder()
|
|
||||||
.setMediaId(videoUri)
|
|
||||||
.setUri(videoUri)
|
|
||||||
.setMediaMetadata(
|
|
||||||
MediaMetadata.Builder()
|
|
||||||
.setArtist(authorName?.ifBlank { null })
|
|
||||||
.setTitle(title?.ifBlank { null } ?: videoUri)
|
|
||||||
.setArtworkUri(
|
|
||||||
try {
|
|
||||||
if (artworkUri != null) {
|
|
||||||
Uri.parse(artworkUri)
|
|
||||||
} else {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
null
|
|
||||||
}
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
.build()
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
GetVideoController(
|
GetVideoController(
|
||||||
mediaItem = mediaItem,
|
mediaItem = mediaItem,
|
||||||
videoUri = videoUri,
|
videoUri = videoUri,
|
||||||
@@ -323,6 +304,50 @@ fun VideoViewInner(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun GetMediaItem(
|
||||||
|
videoUri: String,
|
||||||
|
title: String?,
|
||||||
|
artworkUri: String?,
|
||||||
|
authorName: String?,
|
||||||
|
inner: @Composable (State<MediaItem>) -> Unit
|
||||||
|
) {
|
||||||
|
val mediaItem = produceState<MediaItem?>(
|
||||||
|
initialValue = null,
|
||||||
|
key1 = videoUri
|
||||||
|
) {
|
||||||
|
this.value = MediaItem.Builder()
|
||||||
|
.setMediaId(videoUri)
|
||||||
|
.setUri(videoUri)
|
||||||
|
.setMediaMetadata(
|
||||||
|
MediaMetadata.Builder()
|
||||||
|
.setArtist(authorName?.ifBlank { null })
|
||||||
|
.setTitle(title?.ifBlank { null } ?: videoUri)
|
||||||
|
.setArtworkUri(
|
||||||
|
try {
|
||||||
|
if (artworkUri != null) {
|
||||||
|
Uri.parse(artworkUri)
|
||||||
|
} else {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
null
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
)
|
||||||
|
.build()
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaItem.value?.let {
|
||||||
|
val myState = remember(videoUri) {
|
||||||
|
mutableStateOf(it)
|
||||||
|
}
|
||||||
|
inner(myState)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Immutable
|
@Immutable
|
||||||
sealed class MediaControllerState {
|
sealed class MediaControllerState {
|
||||||
@@ -339,7 +364,7 @@ sealed class MediaControllerState {
|
|||||||
@Composable
|
@Composable
|
||||||
@OptIn(UnstableApi::class)
|
@OptIn(UnstableApi::class)
|
||||||
fun GetVideoController(
|
fun GetVideoController(
|
||||||
mediaItem: MutableState<MediaItem>,
|
mediaItem: State<MediaItem>,
|
||||||
videoUri: String,
|
videoUri: String,
|
||||||
defaultToStart: Boolean = false,
|
defaultToStart: Boolean = false,
|
||||||
nostrUriCallback: String? = null,
|
nostrUriCallback: String? = null,
|
||||||
|
|||||||
Reference in New Issue
Block a user