mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Remember Player instance on recompositions
PiperOrigin-RevId: 641823733
This commit is contained in:
parent
6bb3af527a
commit
009f7360c5
@ -22,6 +22,7 @@ import androidx.activity.enableEdgeToEdge
|
|||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
import androidx.compose.material3.Surface
|
import androidx.compose.material3.Surface
|
||||||
|
import androidx.compose.runtime.remember
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
@ -41,13 +42,15 @@ class MainActivity : ComponentActivity() {
|
|||||||
verticalArrangement = Arrangement.Center,
|
verticalArrangement = Arrangement.Center,
|
||||||
horizontalAlignment = Alignment.CenterHorizontally,
|
horizontalAlignment = Alignment.CenterHorizontally,
|
||||||
) {
|
) {
|
||||||
val exoPlayer =
|
val context = LocalContext.current
|
||||||
ExoPlayer.Builder(LocalContext.current).build().apply {
|
val exoPlayer = remember {
|
||||||
|
ExoPlayer.Builder(context).build().apply {
|
||||||
setMediaItem(MediaItem.fromUri(videos[0]))
|
setMediaItem(MediaItem.fromUri(videos[0]))
|
||||||
prepare()
|
prepare()
|
||||||
playWhenReady = true
|
playWhenReady = true
|
||||||
repeatMode = Player.REPEAT_MODE_ONE
|
repeatMode = Player.REPEAT_MODE_ONE
|
||||||
}
|
}
|
||||||
|
}
|
||||||
PlayerSurface(
|
PlayerSurface(
|
||||||
player = exoPlayer,
|
player = exoPlayer,
|
||||||
surfaceType = SURFACE_TYPE_SURFACE_VIEW,
|
surfaceType = SURFACE_TYPE_SURFACE_VIEW,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user