Last active
March 22, 2021 11:54
-
-
Save halilozercan/f85a85761cd5b24874fb68b6572a1e8c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @Composable | |
| fun VideoPlayer() { | |
| // This is the official way to access current context from Composable functions | |
| val context = ContextAmbient.current | |
| // Do not recreate the player everytime this Composable commits | |
| val exoPlayer = remember { | |
| SimpleExoPlayer.Builder(context).build().apply { | |
| val dataSourceFactory: DataSource.Factory = DefaultDataSourceFactory(context, | |
| Util.getUserAgent(context, context.packageName)) | |
| val source = ProgressiveMediaSource.Factory(dataSourceFactory) | |
| .createMediaSource(Uri.parse( | |
| // Big Buck Bunny from Blender Project | |
| "https://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" | |
| )) | |
| this.prepare(source) | |
| } | |
| } | |
| // Gateway to traditional Android Views | |
| AndroidView( | |
| viewBlock = { context -> | |
| PlayerView(context).apply { | |
| player = exoPlayer | |
| playWhenReady = true | |
| } | |
| } | |
| ) | |
| } |
Author
Yes you are right, this was written for beta01 and an older version of ExoPlayer.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I had to change
viewBlocktofactoryandplayWhenReadyis not a member. But it could be my version of the libraries (compose_version = 1.0.0-beta02). And I'm just starting to understand compose, so expect some misunderstandings.