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

View File

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