diff --git a/Android/VeraxApplication/app/build.gradle.kts b/Android/VeraxApplication/app/build.gradle.kts index 9df79db..2ca3faa 100644 --- a/Android/VeraxApplication/app/build.gradle.kts +++ b/Android/VeraxApplication/app/build.gradle.kts @@ -56,18 +56,20 @@ dependencies { implementation ("com.squareup.retrofit2:converter-gson:2.9.0") - implementation("androidx.core:core-ktx:1.10.1") - implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.6.1") - implementation("androidx.activity:activity-compose:1.7.0") - implementation("androidx.navigation:navigation-compose:2.4.0-alpha08") + implementation("androidx.core:core-ktx:1.12.0") + implementation("androidx.lifecycle:lifecycle-runtime-ktx:2.7.0") + implementation("androidx.activity:activity-compose:1.8.2") + implementation("androidx.navigation:navigation-compose:2.7.7") + + // Jetpack Compose + implementation("androidx.compose.ui:ui:1.6.4") + implementation ("androidx.compose.material:material:1.6.4") + implementation ("androidx.compose.ui:ui-tooling:1.6.4") - /*// Jetpack Compose - implementation 'androidx.compose.ui:ui:1.0.5' - implementation 'androidx.compose.material:material:1.0.5' - implementation 'androidx.compose.ui:ui-tooling:1.0.5' - */ // ExoPlayer - implementation("com.google.android.exoplayer:exoplayer:2.15.1") + implementation ("androidx.media3:media3-session:1.3.0") + implementation("com.google.android.exoplayer:exoplayer-core:2.19.1") + implementation ("com.google.android.exoplayer:exoplayer-ui:2.19.1") implementation(platform("androidx.compose:compose-bom:2023.08.00")) implementation("androidx.compose.ui:ui") diff --git a/Android/VeraxApplication/app/src/main/java/com/example/veraxapplication/ui/article/Article.kt b/Android/VeraxApplication/app/src/main/java/com/example/veraxapplication/ui/article/Article.kt index 1e4876b..c68275e 100644 --- a/Android/VeraxApplication/app/src/main/java/com/example/veraxapplication/ui/article/Article.kt +++ b/Android/VeraxApplication/app/src/main/java/com/example/veraxapplication/ui/article/Article.kt @@ -1,5 +1,6 @@ package com.example.veraxapplication.ui.article +import VideoPlayer import androidx.compose.foundation.BorderStroke import androidx.compose.foundation.Image import androidx.compose.foundation.background @@ -155,7 +156,8 @@ fun AfficherArticle(e : Article){ } "video" -> { Text(text = "Ici une video ..."+ text.toString(), fontSize = 15.sp, textAlign = TextAlign.Start) - //faut je vois comment on fait pour inclure une video ... + // le player video marche a moitiƩ mais honnetenement je comprends pas le soucis + VideoPlayer(videoUrl = text.lien) } } diff --git a/Android/VeraxApplication/app/src/main/java/com/example/veraxapplication/ui/article/VideoPlayer.kt b/Android/VeraxApplication/app/src/main/java/com/example/veraxapplication/ui/article/VideoPlayer.kt index b00b09a..6862ac8 100644 --- a/Android/VeraxApplication/app/src/main/java/com/example/veraxapplication/ui/article/VideoPlayer.kt +++ b/Android/VeraxApplication/app/src/main/java/com/example/veraxapplication/ui/article/VideoPlayer.kt @@ -1,59 +1,44 @@ -package com.example.veraxapplication.ui.article -import android.graphics.drawable.Icon -import android.media.browse.MediaBrowser -import android.net.Uri // pas sur de l'import +import android.view.ViewGroup import androidx.compose.foundation.layout.fillMaxSize -import androidx.compose.foundation.layout.padding -import androidx.compose.material3.Icon -import androidx.compose.material3.IconButton import androidx.compose.runtime.Composable -import androidx.compose.runtime.remember -import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.platform.LocalContext -import androidx.compose.ui.unit.dp +import androidx.compose.ui.platform.LocalLifecycleOwner import androidx.compose.ui.viewinterop.AndroidView -import com.google.android.exoplayer2.SimpleExoPlayer +import com.google.android.exoplayer2.ExoPlayer +import com.google.android.exoplayer2.MediaItem import com.google.android.exoplayer2.ui.PlayerView @Composable -fun VideoPlayer(videoUri : Uri){ +fun VideoPlayer(videoUrl : String){ val context = LocalContext.current - val exoPlayer = remember { - SimpleExoPlayer.Builder(context).build().apply { - setMediaItem(MediaBrowser.MediaItem.fromUri(videoUri)) - prepare() - } + val lifecycleOwner = LocalLifecycleOwner.current + + val player = ExoPlayer.Builder(context).build() + + val playerView = PlayerView(context).apply { + layoutParams = ViewGroup.LayoutParams( + ViewGroup.LayoutParams.MATCH_PARENT, + ViewGroup.LayoutParams.MATCH_PARENT + ) } - val playbackState by exoPlayer.rememberPlaybackState() - val isPlaying = playbackState?.isPlaying ?: false + + val mediaItem = MediaItem.Builder() + .setUri(videoUrl) + .build() + + player.setMediaItem(mediaItem) + player.prepare() + player.play() AndroidView( - factory = { context -> - PlayerView(context).apply { - player = exoPlayer - } - }, - modifier = Modifier.fillMaxSize() + factory = { context -> playerView }, + modifier = Modifier.fillMaxSize(), + update = { view -> + view.player = player + } ) - IconButton( - onClick = { - if (isPlaying) { - exoPlayer.pause() - } else { - exoPlayer.play() - } - }, - modifier = Modifier - .padding(16.dp) - ) { - /*Icon( - imageVector = if (isPlaying) Icons.Filled.Pause else Icons.Filled.PlayArrow, - contentDescription = if (isPlaying) "Pause" else "Play", - tint = Color.White, - modifier = Modifier.size(48.dp) - )*/ - } -} \ No newline at end of file + +}