Skip to content

Instantly share code, notes, and snippets.

@ademirqueiroga
Last active January 29, 2023 10:47
Show Gist options
  • Save ademirqueiroga/8cdbdd0af9494f5da6a4454e43c01121 to your computer and use it in GitHub Desktop.
Save ademirqueiroga/8cdbdd0af9494f5da6a4454e43c01121 to your computer and use it in GitHub Desktop.
BasicMediaPlayerAdapter.kt
class BasicMediaPlayerAdapter(context: Context) : MediaPlayerAdapter(context) {
val playlist = ArrayList<Movie>()
var playlistPosition = 0
private set
override fun next() = loadMovie((playlistPosition + 1).mod(playlist.size))
override fun previous() = loadMovie((playlistPosition - 1).mod(playlist.size))
override fun fastForward() = seekTo(currentPosition + 10_000)
override fun rewind() = seekTo(currentPosition - 10_000)
override fun getSupportedActions(): Long {
return (ACTION_SKIP_TO_PREVIOUS xor
ACTION_REWIND xor
ACTION_PLAY_PAUSE xor
ACTION_FAST_FORWARD xor
ACTION_SKIP_TO_NEXT).toLong()
}
fun loadMovie(playlistPosition: Int) {
this.playlistPosition = playlistPosition
setDataSource(Uri.parse(playlist[playlistPosition].videoUrl))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment