Skip to content

Instantly share code, notes, and snippets.

@halilozercan
Last active March 4, 2021 06:54
Show Gist options
  • Save halilozercan/07ee6139173ea830fe591fbf2e7d046e to your computer and use it in GitHub Desktop.
Save halilozercan/07ee6139173ea830fe591fbf2e7d046e to your computer and use it in GitHub Desktop.
@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