parent
af3ff9dacc
commit
880ce7c38c
@ -0,0 +1,57 @@
|
|||||||
|
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 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.viewinterop.AndroidView
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun VideoPlayer(videoUri : Uri){
|
||||||
|
val context = LocalContext.current
|
||||||
|
val exoPlayer = remember {
|
||||||
|
SimpleExoPlayer.Builder(context).build().apply {
|
||||||
|
setMediaItem(MediaBrowser.MediaItem.fromUri(videoUri))
|
||||||
|
prepare()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
val playbackState by exoPlayer.rememberPlaybackState()
|
||||||
|
val isPlaying = playbackState?.isPlaying ?: false
|
||||||
|
|
||||||
|
AndroidView(
|
||||||
|
factory = { context ->
|
||||||
|
PlayerView(context).apply {
|
||||||
|
player = exoPlayer
|
||||||
|
}
|
||||||
|
},
|
||||||
|
modifier = Modifier.fillMaxSize()
|
||||||
|
)
|
||||||
|
|
||||||
|
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)
|
||||||
|
)*/
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue