Fix circle video playback and recorder compatibility
This commit is contained in:
@@ -104,6 +104,7 @@ dependencies {
|
||||
implementation("io.coil-kt:coil-gif:2.7.0")
|
||||
implementation("io.coil-kt:coil-video:2.7.0")
|
||||
implementation("androidx.media3:media3-exoplayer:1.4.1")
|
||||
implementation("androidx.media3:media3-ui:1.4.1")
|
||||
implementation("androidx.media3:media3-datasource:1.4.1")
|
||||
implementation("androidx.media3:media3-datasource-okhttp:1.4.1")
|
||||
implementation("androidx.camera:camera-core:1.4.2")
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
<application
|
||||
android:name=".MessengerApplication"
|
||||
android:allowBackup="true"
|
||||
android:enableOnBackInvokedCallback="true"
|
||||
android:icon="@android:drawable/sym_def_app_icon"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@android:drawable/sym_def_app_icon"
|
||||
|
||||
@@ -197,6 +197,11 @@ import androidx.camera.video.VideoCapture
|
||||
import androidx.camera.video.VideoRecordEvent
|
||||
import androidx.camera.view.PreviewView
|
||||
import androidx.compose.ui.window.Dialog
|
||||
import androidx.media3.common.MediaItem
|
||||
import androidx.media3.common.Player
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
import androidx.media3.ui.AspectRatioFrameLayout
|
||||
import androidx.media3.ui.PlayerView
|
||||
|
||||
@Composable
|
||||
fun ChatRoute(
|
||||
@@ -2319,7 +2324,7 @@ private fun CircleVideoRecorderDialog(
|
||||
setSurfaceProvider(previewView.surfaceProvider)
|
||||
}
|
||||
val recorder = Recorder.Builder()
|
||||
.setQualitySelector(QualitySelector.from(Quality.SD))
|
||||
.setQualitySelector(QualitySelector.from(Quality.HD))
|
||||
.build()
|
||||
val capture = VideoCapture.withOutput(recorder)
|
||||
runCatching {
|
||||
@@ -3115,6 +3120,21 @@ private fun VideoAttachmentCard(
|
||||
|
||||
@Composable
|
||||
private fun CircleVideoAttachmentPlayer(url: String) {
|
||||
val context = LocalContext.current
|
||||
val player = remember(url) {
|
||||
ExoPlayer.Builder(context).build().apply {
|
||||
setMediaItem(MediaItem.fromUri(url))
|
||||
repeatMode = Player.REPEAT_MODE_ONE
|
||||
volume = 0f
|
||||
playWhenReady = true
|
||||
prepare()
|
||||
}
|
||||
}
|
||||
DisposableEffect(player) {
|
||||
onDispose {
|
||||
player.release()
|
||||
}
|
||||
}
|
||||
Column(
|
||||
modifier = Modifier
|
||||
.fillMaxWidth()
|
||||
@@ -3125,22 +3145,17 @@ private fun CircleVideoAttachmentPlayer(url: String) {
|
||||
) {
|
||||
AndroidView(
|
||||
factory = { context ->
|
||||
VideoView(context).apply {
|
||||
setVideoPath(url)
|
||||
setOnPreparedListener { player ->
|
||||
player.isLooping = true
|
||||
player.setVolume(0f, 0f)
|
||||
start()
|
||||
}
|
||||
PlayerView(context).apply {
|
||||
useController = false
|
||||
resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM
|
||||
this.player = player
|
||||
}
|
||||
},
|
||||
modifier = Modifier
|
||||
.size(220.dp)
|
||||
.clip(CircleShape),
|
||||
update = { view ->
|
||||
if (!view.isPlaying) {
|
||||
runCatching { view.start() }
|
||||
}
|
||||
view.player = player
|
||||
},
|
||||
)
|
||||
Text(stringResource(id = R.string.chat_circle_video), style = MaterialTheme.typography.labelSmall)
|
||||
|
||||
Reference in New Issue
Block a user