diff options
author | daniel oeh <daniel.oeh@gmail.com> | 2012-07-27 15:46:56 +0200 |
---|---|---|
committer | daniel oeh <daniel.oeh@gmail.com> | 2012-07-27 15:46:56 +0200 |
commit | b155a4cdf94eb74423cedd54cfd7d0ed376ac4e0 (patch) | |
tree | 998f337e87034155372f7cd168b764feb9b7ebbc /src/de/danoeh/antennapod/service | |
parent | e23c1a0143996784f2c9c7563ae45445403be501 (diff) | |
download | AntennaPod-b155a4cdf94eb74423cedd54cfd7d0ed376ac4e0.zip |
Completed sleep timer implementation
Diffstat (limited to 'src/de/danoeh/antennapod/service')
-rw-r--r-- | src/de/danoeh/antennapod/service/PlaybackService.java | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/de/danoeh/antennapod/service/PlaybackService.java b/src/de/danoeh/antennapod/service/PlaybackService.java index df519984e..af8b50060 100644 --- a/src/de/danoeh/antennapod/service/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/PlaybackService.java @@ -494,6 +494,7 @@ public class PlaybackService extends Service { player.pause(); if (abandonFocus) { audioManager.abandonAudioFocus(audioFocusChangeListener); + disableSleepTimer(); } if (positionSaver != null) { positionSaver.cancel(true); @@ -641,6 +642,14 @@ public class PlaybackService extends Service { return sleepTimer != null && sleepTimer.isWaiting(); } + public long getSleepTimerTimeLeft() { + if (sleepTimerActive()) { + return sleepTimer.getWaitingTime(); + } else { + return 0; + } + } + /** * Pauses playback when the headset is disconnected and the preference is * set @@ -735,7 +744,7 @@ public class PlaybackService extends Service { class SleepTimer extends AsyncTask<Void, Void, Void> { private static final String TAG = "SleepTimer"; private static final long UPDATE_INTERVALL = 1000L; - private long waitingTime; + private volatile long waitingTime; private boolean isWaiting; public SleepTimer(long waitingTime) { @@ -753,9 +762,14 @@ public class PlaybackService extends Service { Thread.sleep(UPDATE_INTERVALL); waitingTime -= UPDATE_INTERVALL; - if (waitingTime <= 0 && status == PlayerStatus.PLAYING) { - Log.d(TAG, "Pausing playback"); - pause(true); + if (waitingTime <= 0) { + if (AppConfig.DEBUG) + Log.d(TAG, "Waiting completed"); + if (status == PlayerStatus.PLAYING) { + if (AppConfig.DEBUG) + Log.d(TAG, "Pausing playback"); + pause(true); + } return null; } } catch (InterruptedException e) { @@ -764,7 +778,7 @@ public class PlaybackService extends Service { } return null; } - + @SuppressLint("NewApi") public void executeAsync() { if (android.os.Build.VERSION.SDK_INT > android.os.Build.VERSION_CODES.GINGERBREAD_MR1) { @@ -773,7 +787,7 @@ public class PlaybackService extends Service { execute(); } } - + @Override protected void onCancelled() { isWaiting = false; |