Fix circle video playback and recorder compatibility
Some checks failed
Android CI / android (push) Failing after 6m47s
Android Release / release (push) Failing after 6m1s
CI / test (push) Has started running

This commit is contained in:
2026-03-11 22:46:34 +03:00
parent cf53123724
commit e6f1727800
3 changed files with 28 additions and 11 deletions

View File

@@ -104,6 +104,7 @@ dependencies {
implementation("io.coil-kt:coil-gif:2.7.0") implementation("io.coil-kt:coil-gif:2.7.0")
implementation("io.coil-kt:coil-video:2.7.0") implementation("io.coil-kt:coil-video:2.7.0")
implementation("androidx.media3:media3-exoplayer:1.4.1") 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:1.4.1")
implementation("androidx.media3:media3-datasource-okhttp:1.4.1") implementation("androidx.media3:media3-datasource-okhttp:1.4.1")
implementation("androidx.camera:camera-core:1.4.2") implementation("androidx.camera:camera-core:1.4.2")

View File

@@ -9,6 +9,7 @@
<application <application
android:name=".MessengerApplication" android:name=".MessengerApplication"
android:allowBackup="true" android:allowBackup="true"
android:enableOnBackInvokedCallback="true"
android:icon="@android:drawable/sym_def_app_icon" android:icon="@android:drawable/sym_def_app_icon"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@android:drawable/sym_def_app_icon" android:roundIcon="@android:drawable/sym_def_app_icon"

View File

@@ -197,6 +197,11 @@ import androidx.camera.video.VideoCapture
import androidx.camera.video.VideoRecordEvent import androidx.camera.video.VideoRecordEvent
import androidx.camera.view.PreviewView import androidx.camera.view.PreviewView
import androidx.compose.ui.window.Dialog 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 @Composable
fun ChatRoute( fun ChatRoute(
@@ -2319,7 +2324,7 @@ private fun CircleVideoRecorderDialog(
setSurfaceProvider(previewView.surfaceProvider) setSurfaceProvider(previewView.surfaceProvider)
} }
val recorder = Recorder.Builder() val recorder = Recorder.Builder()
.setQualitySelector(QualitySelector.from(Quality.SD)) .setQualitySelector(QualitySelector.from(Quality.HD))
.build() .build()
val capture = VideoCapture.withOutput(recorder) val capture = VideoCapture.withOutput(recorder)
runCatching { runCatching {
@@ -3115,6 +3120,21 @@ private fun VideoAttachmentCard(
@Composable @Composable
private fun CircleVideoAttachmentPlayer(url: String) { 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( Column(
modifier = Modifier modifier = Modifier
.fillMaxWidth() .fillMaxWidth()
@@ -3125,22 +3145,17 @@ private fun CircleVideoAttachmentPlayer(url: String) {
) { ) {
AndroidView( AndroidView(
factory = { context -> factory = { context ->
VideoView(context).apply { PlayerView(context).apply {
setVideoPath(url) useController = false
setOnPreparedListener { player -> resizeMode = AspectRatioFrameLayout.RESIZE_MODE_ZOOM
player.isLooping = true this.player = player
player.setVolume(0f, 0f)
start()
}
} }
}, },
modifier = Modifier modifier = Modifier
.size(220.dp) .size(220.dp)
.clip(CircleShape), .clip(CircleShape),
update = { view -> update = { view ->
if (!view.isPlaying) { view.player = player
runCatching { view.start() }
}
}, },
) )
Text(stringResource(id = R.string.chat_circle_video), style = MaterialTheme.typography.labelSmall) Text(stringResource(id = R.string.chat_circle_video), style = MaterialTheme.typography.labelSmall)