Skip to content

Instantly share code, notes, and snippets.

@dreadjr
Last active January 4, 2020 01:05
Show Gist options
  • Save dreadjr/f1765e1bd8d67ddb88ddb9502d96e25c to your computer and use it in GitHub Desktop.
Save dreadjr/f1765e1bd8d67ddb88ddb9502d96e25c to your computer and use it in GitHub Desktop.
// Need to update track name, can we just get from media?
// Need to lock controls after playing
// Still not updating time right away
// trigger STATE_END?
player.setPlayWhenReady(false);
player.seekTo(C.TIME_UNSET);
PlayerMusicActivity ::: in override fun onCreate(savedInstanceState: Bundle?) {
class PlayerControlDispatcher : DefaultControlDispatcher() {
override fun dispatchSetPlayWhenReady(player1: com.google.android.exoplayer2.Player, playWhenReady: Boolean): Boolean {
if (!player.isPlaying()) {
Log.e(ExoPlayerLibraryInfo.TAG, "Play button pressed")
// recyclerView.isEnabled = false
val uris = buildURIList(songAdapter?.getPlayList())
// txt_player.text = getString(R.string.now_playing) + "\n" + song?.songTitle
player?.play(*uris)
txt_player_session.text = "Total Session Time : ${songAdapter?.getSessionDuration()}"
// Play button clicked
} else {
// Paused button clicked
Log.e(ExoPlayerLibraryInfo.TAG, "Stop button pressed")
// songAdapter?.resetAdapterSelection()
// Log.e(TAG, "Playback ended!")
// val i = Intent(this@PlayMusicActivity, SessionDetailActivity::class.java)
// i.putExtra("Time", getPlayerTime(0))
// startActivity(i)
}
return super.dispatchSetPlayWhenReady(player1, playWhenReady)
}
override fun dispatchStop(
player1: com.google.android.exoplayer2.Player,
reset: Boolean
): Boolean {
Log.e(ExoPlayerLibraryInfo.TAG, "Stop button pressed")
return super.dispatchStop(player1, reset)
}
}
exoPlayerUIView.setControlDispatcher(PlayerControlDispatcher())
Total Elapsed timber
exoPlayerUIView.setShowMultiWindowTimeBar(true)
Update Session screen
text_session_time.text = time.toString()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment