Skip to content

Instantly share code, notes, and snippets.

@nazmulidris
Created March 8, 2018 23:01
Show Gist options
  • Select an option

  • Save nazmulidris/6d02ac7e4f64ad86c61a2d081c18ca49 to your computer and use it in GitHub Desktop.

Select an option

Save nazmulidris/6d02ac7e4f64ad86c61a2d081c18ca49 to your computer and use it in GitHub Desktop.
class PlayerHolder(...) : AnkoLogger {
...
fun start() {
// Load media.
player.prepare(...)
// Restore state (after onResume()/onStart())
with(playerState) {
// Start playback when media has buffered enough
// (whenReady is true by default).
player.playWhenReady = whenReady
player.seekTo(window, position)
}
info { "SimpleExoPlayer is started" }
}
fun stop() {
with(player) {
// Save state
with(state) {
position = currentPosition
window = currentWindowIndex
whenReady = playWhenReady
}
// Stop the player.
stop()
}
info { "SimpleExoPlayer is released" }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment