Skip to content

Instantly share code, notes, and snippets.

@halilozercan
Created July 31, 2020 10:21
Show Gist options
  • Select an option

  • Save halilozercan/79f5c2eefdd2b5242f9c9b17b31420c9 to your computer and use it in GitHub Desktop.

Select an option

Save halilozercan/79f5c2eefdd2b5242f9c9b17b31420c9 to your computer and use it in GitHub Desktop.
class PlayerController(
private val context: Context
) {
private val exoPlayer by lazy {
SimpleExoPlayer.Builder(context).build()
}
fun prepare(sourceUrl: String) {
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
sourceUrl
))
exoPlayer.prepare(source)
}
fun setPlayerView(playerView: PlayerView) {
playerView.player = exoPlayer
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment