Last active
March 4, 2021 06:54
-
-
Save halilozercan/07ee6139173ea830fe591fbf2e7d046e 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 = LocalContext.current | |
// Do not recreate the player everytime this Composable commits | |
val exoPlayer = remember(context) { | |
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) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment