summaryrefslogtreecommitdiff
path: root/src/de/podfetcher
diff options
context:
space:
mode:
authordaniel oeh <daniel.oeh@gmail.com>2012-07-07 16:37:21 +0200
committerdaniel oeh <daniel.oeh@gmail.com>2012-07-07 16:37:21 +0200
commit54741495dfa0fa5681c73c6b61a74dc58f0ab724 (patch)
treed55478f060d446cbb458f44f97d994fbc20e2687 /src/de/podfetcher
parent8ae87e2a567031f913687794a95882c668659942 (diff)
downloadAntennaPod-54741495dfa0fa5681c73c6b61a74dc58f0ab724.zip
Implemented Widget update calls in PlaybackService
Diffstat (limited to 'src/de/podfetcher')
-rw-r--r--src/de/podfetcher/service/PlaybackService.java51
1 files changed, 50 insertions, 1 deletions
diff --git a/src/de/podfetcher/service/PlaybackService.java b/src/de/podfetcher/service/PlaybackService.java
index de8527fd0..81fd1501e 100644
--- a/src/de/podfetcher/service/PlaybackService.java
+++ b/src/de/podfetcher/service/PlaybackService.java
@@ -85,6 +85,7 @@ public class PlaybackService extends Service {
private FeedManager manager;
private PlayerStatus status;
private PositionSaver positionSaver;
+ private WidgetUpdateWorker widgetUpdater;
private PlayerStatus statusBeforeSeek;
@@ -128,6 +129,8 @@ public class PlaybackService extends Service {
audioManager.unregisterMediaButtonEventReceiver(mediaButtonReceiver);
audioManager.abandonAudioFocus(audioFocusChangeListener);
player.release();
+ stopWidgetUpdater();
+ updateWidget();
}
@Override
@@ -394,6 +397,7 @@ public class PlaybackService extends Service {
FeedItem nextItem = manager.getFirstQueueItem();
if (nextItem == null) {
Log.d(TAG, "No more items in queue");
+ stopWidgetUpdater();
setStatus(PlayerStatus.STOPPED);
stopForeground(true);
} else {
@@ -428,6 +432,7 @@ public class PlaybackService extends Service {
positionSaver.cancel(true);
}
saveCurrentPosition();
+ stopWidgetUpdater();
setStatus(PlayerStatus.PAUSED);
stopForeground(true);
}
@@ -460,6 +465,7 @@ public class PlaybackService extends Service {
player.seekTo((int) media.getPosition());
setStatus(PlayerStatus.PLAYING);
setupPositionSaver();
+ setupWidgetUpdater();
setupNotification();
pausedBecauseOfTransientAudiofocusLoss = false;
} else {
@@ -472,7 +478,7 @@ public class PlaybackService extends Service {
Log.d(TAG, "Setting status to " + newStatus);
status = newStatus;
sendBroadcast(new Intent(ACTION_PLAYER_STATUS_CHANGED));
- sendBroadcast(new Intent(PlayerWidget.FORCE_WIDGET_UPDATE));
+ updateWidget();
}
private void sendNotificationBroadcast(int type, int code) {
@@ -526,6 +532,24 @@ public class PlaybackService extends Service {
media.setPosition(player.getCurrentPosition());
manager.setFeedMedia(this, media);
}
+
+ private void stopWidgetUpdater() {
+ if (widgetUpdater != null) {
+ widgetUpdater.cancel(true);
+ }
+ }
+
+ private void setupWidgetUpdater() {
+ if (widgetUpdater == null || widgetUpdater.isCancelled()) {
+ widgetUpdater = new WidgetUpdateWorker();
+ widgetUpdater.execute();
+ }
+ }
+
+ private void updateWidget() {
+ Log.d(TAG, "Sending widget update request");
+ PlaybackService.this.sendBroadcast(new Intent(PlayerWidget.FORCE_WIDGET_UPDATE));
+ }
public PlayerStatus getStatus() {
return status;
@@ -564,6 +588,31 @@ public class PlaybackService extends Service {
}
+ /** Notifies the player widget in the specified intervall */
+ class WidgetUpdateWorker extends AsyncTask<Void, Void, Void> {
+ private static final String TAG = "WidgetUpdateWorker";
+ private static final int NOTIFICATION_INTERVALL = 2000;
+
+ @Override
+ protected void onProgressUpdate(Void... values) {
+ updateWidget();
+ }
+
+ @Override
+ protected Void doInBackground(Void... params) {
+ while (PlaybackService.isRunning && !isCancelled()) {
+ publishProgress();
+ try {
+ Thread.sleep(NOTIFICATION_INTERVALL);
+ } catch (InterruptedException e) {
+ return null;
+ }
+ }
+ return null;
+ }
+
+ }
+
public boolean isPlayingVideo() {
return playingVideo;
}