mirror of
https://github.com/AntennaPod/AntennaPod.git
synced 2025-12-01 12:31:45 +00:00
Implemented Widget update calls in PlaybackService
This commit is contained in:
@ -85,6 +85,7 @@ public class PlaybackService extends Service {
|
|||||||
private FeedManager manager;
|
private FeedManager manager;
|
||||||
private PlayerStatus status;
|
private PlayerStatus status;
|
||||||
private PositionSaver positionSaver;
|
private PositionSaver positionSaver;
|
||||||
|
private WidgetUpdateWorker widgetUpdater;
|
||||||
|
|
||||||
private PlayerStatus statusBeforeSeek;
|
private PlayerStatus statusBeforeSeek;
|
||||||
|
|
||||||
@ -128,6 +129,8 @@ public class PlaybackService extends Service {
|
|||||||
audioManager.unregisterMediaButtonEventReceiver(mediaButtonReceiver);
|
audioManager.unregisterMediaButtonEventReceiver(mediaButtonReceiver);
|
||||||
audioManager.abandonAudioFocus(audioFocusChangeListener);
|
audioManager.abandonAudioFocus(audioFocusChangeListener);
|
||||||
player.release();
|
player.release();
|
||||||
|
stopWidgetUpdater();
|
||||||
|
updateWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -394,6 +397,7 @@ public class PlaybackService extends Service {
|
|||||||
FeedItem nextItem = manager.getFirstQueueItem();
|
FeedItem nextItem = manager.getFirstQueueItem();
|
||||||
if (nextItem == null) {
|
if (nextItem == null) {
|
||||||
Log.d(TAG, "No more items in queue");
|
Log.d(TAG, "No more items in queue");
|
||||||
|
stopWidgetUpdater();
|
||||||
setStatus(PlayerStatus.STOPPED);
|
setStatus(PlayerStatus.STOPPED);
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
} else {
|
} else {
|
||||||
@ -428,6 +432,7 @@ public class PlaybackService extends Service {
|
|||||||
positionSaver.cancel(true);
|
positionSaver.cancel(true);
|
||||||
}
|
}
|
||||||
saveCurrentPosition();
|
saveCurrentPosition();
|
||||||
|
stopWidgetUpdater();
|
||||||
setStatus(PlayerStatus.PAUSED);
|
setStatus(PlayerStatus.PAUSED);
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
}
|
}
|
||||||
@ -460,6 +465,7 @@ public class PlaybackService extends Service {
|
|||||||
player.seekTo((int) media.getPosition());
|
player.seekTo((int) media.getPosition());
|
||||||
setStatus(PlayerStatus.PLAYING);
|
setStatus(PlayerStatus.PLAYING);
|
||||||
setupPositionSaver();
|
setupPositionSaver();
|
||||||
|
setupWidgetUpdater();
|
||||||
setupNotification();
|
setupNotification();
|
||||||
pausedBecauseOfTransientAudiofocusLoss = false;
|
pausedBecauseOfTransientAudiofocusLoss = false;
|
||||||
} else {
|
} else {
|
||||||
@ -472,7 +478,7 @@ public class PlaybackService extends Service {
|
|||||||
Log.d(TAG, "Setting status to " + newStatus);
|
Log.d(TAG, "Setting status to " + newStatus);
|
||||||
status = newStatus;
|
status = newStatus;
|
||||||
sendBroadcast(new Intent(ACTION_PLAYER_STATUS_CHANGED));
|
sendBroadcast(new Intent(ACTION_PLAYER_STATUS_CHANGED));
|
||||||
sendBroadcast(new Intent(PlayerWidget.FORCE_WIDGET_UPDATE));
|
updateWidget();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendNotificationBroadcast(int type, int code) {
|
private void sendNotificationBroadcast(int type, int code) {
|
||||||
@ -526,6 +532,24 @@ public class PlaybackService extends Service {
|
|||||||
media.setPosition(player.getCurrentPosition());
|
media.setPosition(player.getCurrentPosition());
|
||||||
manager.setFeedMedia(this, media);
|
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() {
|
public PlayerStatus getStatus() {
|
||||||
return status;
|
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() {
|
public boolean isPlayingVideo() {
|
||||||
return playingVideo;
|
return playingVideo;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user