From abe353b3f1ac9197d4f1450db7b95808f9bbe6cc Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Sun, 3 May 2015 13:43:44 +0200 Subject: [PATCH] save playlist state while releasing the wake lock --- .../android/vanilla/PlaybackService.java | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index a7526f7c..c09f109c 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -203,7 +203,10 @@ public final class PlaybackService extends Service * Defer entering deep sleep for this time (in ms). */ private static final int SLEEP_STATE_DELAY = 60000; - + /** + * Save the current playlist state on queue changes after this time (in ms). + */ + private static final int SAVE_STATE_DELAY = 5000; /** * If set, music will play. */ @@ -560,7 +563,6 @@ public final class PlaybackService extends Service enterSleepState(); if (mMediaPlayer != null) { - saveState(mMediaPlayer.getCurrentPosition()); mMediaPlayer.release(); mMediaPlayer = null; } @@ -669,9 +671,12 @@ public final class PlaybackService extends Service */ private void enterSleepState() { - if (mMediaPlayerAudioFxActive) { - mMediaPlayer.closeAudioFx(); - mMediaPlayerAudioFxActive = false; + if (mMediaPlayer != null) { + if (mMediaPlayerAudioFxActive) { + mMediaPlayer.closeAudioFx(); + mMediaPlayerAudioFxActive = false; + } + saveState(mMediaPlayer.getCurrentPosition()); } if (mWakeLock != null && mWakeLock.isHeld()) @@ -1724,7 +1729,7 @@ public final class PlaybackService extends Service public void timelineChanged() { mHandler.removeMessages(SAVE_STATE); - mHandler.sendEmptyMessageDelayed(SAVE_STATE, 5000); + mHandler.sendEmptyMessageDelayed(SAVE_STATE, SAVE_STATE_DELAY); // Trigger a gappless update for the new timeline // This might get canceled if setCurrentSong() also fired a call