Introduce postRunnable helper function

This commit is contained in:
tzugen 2021-03-24 14:10:27 +01:00
parent 93eced9516
commit 493a587b37
No known key found for this signature in database
GPG Key ID: 61E9C34BC10EC930
1 changed files with 14 additions and 10 deletions

View File

@ -240,17 +240,15 @@ class LocalMediaPlayer(private val audioFocusHandler: AudioFocusHandler, private
// FIXME: Why is currentPlaying passed here and not nextPlaying?!
attachHandlersToPlayer(mediaPlayer, currentPlaying!!, false)
if (onNextSongRequested != null) {
val mainHandler = Handler(context.mainLooper)
val myRunnable = Runnable { onNextSongRequested!!.run() }
mainHandler.post(myRunnable)
}
postRunnable(onNextSongRequested)
// Proxy should not be being used here since the next player was already setup to play
proxy?.stop()
proxy = null
}
@Synchronized
fun pause() {
try {
@ -479,11 +477,9 @@ class LocalMediaPlayer(private val audioFocusHandler: AudioFocusHandler, private
setPlayerState(PlayerState.PAUSED)
}
}
if (onPrepared != null) {
val mainHandler = Handler(context.mainLooper)
val myRunnable = Runnable { onPrepared!!.run() }
mainHandler.post(myRunnable)
}
postRunnable(onPrepared)
}
attachHandlersToPlayer(mediaPlayer, downloadFile, partial)
mediaPlayer.prepareAsync()
@ -724,4 +720,12 @@ class LocalMediaPlayer(private val audioFocusHandler: AudioFocusHandler, private
Timber.w(x, "Next Media player error")
nextMediaPlayer!!.reset()
}
private fun postRunnable(runnable: Runnable?) {
if (runnable != null) {
val mainHandler = Handler(context.mainLooper)
val myRunnable = Runnable { runnable.run() }
mainHandler.post(myRunnable)
}
}
}