When continuous playback is disabled, show next episode in notification
This commit is contained in:
parent
c3b35f7d8d
commit
b6fcc8bc5a
|
@ -947,14 +947,10 @@ public class LocalPSMP extends PlaybackServiceMediaPlayer {
|
|||
// is an episode in the queue left.
|
||||
// Start playback immediately if continuous playback is enabled
|
||||
nextMedia = callback.getNextInQueue(currentMedia);
|
||||
|
||||
boolean playNextEpisode = isPlaying &&
|
||||
nextMedia != null &&
|
||||
UserPreferences.isFollowQueue();
|
||||
|
||||
boolean playNextEpisode = isPlaying && nextMedia != null;
|
||||
if (playNextEpisode) {
|
||||
Log.d(TAG, "Playback of next episode will start immediately.");
|
||||
} else if (nextMedia == null){
|
||||
} else if (nextMedia == null) {
|
||||
Log.d(TAG, "No more episodes available to play");
|
||||
} else {
|
||||
Log.d(TAG, "Loading next episode, but not playing automatically.");
|
||||
|
|
|
@ -736,7 +736,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
mediaPlayer.playMediaObject(playable, PlaybackPreferences.getCurrentEpisodeIsStream(),
|
||||
true, true);
|
||||
stateManager.validStartCommandWasReceived();
|
||||
PlaybackService.this.updateMediaSessionMetadata(playable);
|
||||
updateNotificationAndMediaSession(playable);
|
||||
addPlayableToQueue(playable);
|
||||
}, error -> {
|
||||
Log.d(TAG, "Playable was not loaded from preferences. Stopping service.");
|
||||
|
@ -757,7 +757,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
public void notifyVideoSurfaceAbandoned() {
|
||||
mediaPlayer.pause(true, false);
|
||||
mediaPlayer.resetVideoSurface();
|
||||
setupNotification(getPlayable());
|
||||
updateNotificationAndMediaSession(getPlayable());
|
||||
stateManager.stopForeground(!UserPreferences.isPersistNotify());
|
||||
}
|
||||
|
||||
|
@ -813,7 +813,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
case INITIALIZED:
|
||||
PlaybackPreferences.writeMediaPlaying(mediaPlayer.getPSMPInfo().playable,
|
||||
mediaPlayer.getPSMPInfo().playerStatus, mediaPlayer.isStreaming());
|
||||
setupNotification(newInfo);
|
||||
updateNotificationAndMediaSession(newInfo.playable);
|
||||
break;
|
||||
|
||||
case PREPARED:
|
||||
|
@ -825,7 +825,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
// do not remove notification on pause based on user pref and whether android version supports expanded notifications
|
||||
// Change [Play] button to [Pause]
|
||||
setupNotification(newInfo);
|
||||
updateNotificationAndMediaSession(newInfo.playable);
|
||||
} else if (!UserPreferences.isPersistNotify() && !isCasting) {
|
||||
// remove notification on pause
|
||||
stateManager.stopForeground(true);
|
||||
|
@ -841,7 +841,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
|
||||
case PLAYING:
|
||||
PlaybackPreferences.writePlayerStatus(mediaPlayer.getPlayerStatus());
|
||||
setupNotification(newInfo);
|
||||
updateNotificationAndMediaSession(newInfo.playable);
|
||||
setupPositionObserver();
|
||||
stateManager.validStartCommandWasReceived();
|
||||
// set sleep timer if auto-enabled
|
||||
|
@ -868,7 +868,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
|
||||
@Override
|
||||
public void shouldStop() {
|
||||
setupNotification(getPlayable()); // Stops foreground if not playing
|
||||
updateNotificationAndMediaSession(getPlayable()); // Stops foreground if not playing
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -887,7 +887,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
if (reloadUI) {
|
||||
sendNotificationBroadcast(NOTIFICATION_TYPE_RELOAD, 0);
|
||||
}
|
||||
PlaybackService.this.updateMediaSessionMetadata(getPlayable());
|
||||
updateNotificationAndMediaSession(getPlayable());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -905,8 +905,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
// Playable is being streamed and does not have a duration specified in the feed
|
||||
playable.setDuration(mediaPlayer.getDuration());
|
||||
DBWriter.setFeedMedia((FeedMedia) playable);
|
||||
updateMediaSessionMetadata(playable);
|
||||
setupNotification(playable);
|
||||
updateNotificationAndMediaSession(playable);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -1000,6 +999,12 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
return null;
|
||||
}
|
||||
|
||||
if (!UserPreferences.isFollowQueue()) {
|
||||
Log.d(TAG, "getNextInQueue(), but follow queue is not enabled.");
|
||||
updateNotificationAndMediaSession(nextItem.getMedia());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!nextItem.getMedia().localFileAvailable() && !NetworkUtils.isStreamingAllowed()
|
||||
&& UserPreferences.isFollowQueue() && !nextItem.getFeed().isLocalFeed()) {
|
||||
displayStreamingNotAllowedNotification(
|
||||
|
@ -1273,6 +1278,11 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP));
|
||||
}
|
||||
|
||||
private void updateNotificationAndMediaSession(final Playable p) {
|
||||
updateMediaSessionMetadata(p);
|
||||
setupNotification(p);
|
||||
}
|
||||
|
||||
private void updateMediaSessionMetadata(final Playable p) {
|
||||
if (p == null || mediaSession == null) {
|
||||
return;
|
||||
|
@ -1314,10 +1324,6 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
/**
|
||||
* Prepares notification and starts the service in the foreground.
|
||||
*/
|
||||
private void setupNotification(final PlaybackServiceMediaPlayer.PSMPInfo info) {
|
||||
setupNotification(info.playable);
|
||||
}
|
||||
|
||||
private synchronized void setupNotification(final Playable playable) {
|
||||
Log.d(TAG, "setupNotification");
|
||||
if (playableIconLoaderThread != null) {
|
||||
|
@ -1898,7 +1904,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
private final SharedPreferences.OnSharedPreferenceChangeListener prefListener =
|
||||
(sharedPreferences, key) -> {
|
||||
if (UserPreferences.PREF_LOCKSCREEN_BACKGROUND.equals(key)) {
|
||||
updateMediaSessionMetadata(getPlayable());
|
||||
updateNotificationAndMediaSession(getPlayable());
|
||||
} else {
|
||||
flavorHelper.onSharedPreference(key);
|
||||
}
|
||||
|
@ -1961,7 +1967,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
@Override
|
||||
public void setupNotification(boolean connected, PlaybackServiceMediaPlayer.PSMPInfo info) {
|
||||
if (connected) {
|
||||
PlaybackService.this.setupNotification(info);
|
||||
PlaybackService.this.updateNotificationAndMediaSession(info.playable);
|
||||
} else {
|
||||
PlayerStatus status = info.playerStatus;
|
||||
if ((status == PlayerStatus.PLAYING ||
|
||||
|
@ -1969,7 +1975,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
|
|||
status == PlayerStatus.PREPARING ||
|
||||
UserPreferences.isPersistNotify()) &&
|
||||
android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||
PlaybackService.this.setupNotification(info);
|
||||
PlaybackService.this.updateNotificationAndMediaSession(info.playable);
|
||||
} else if (!UserPreferences.isPersistNotify()) {
|
||||
stateManager.stopForeground(true);
|
||||
}
|
||||
|
|
|
@ -274,13 +274,13 @@ public abstract class PlaybackController {
|
|||
*/
|
||||
private void handleStatus() {
|
||||
Log.d(TAG, "status: " + status.toString());
|
||||
checkMediaInfoLoaded();
|
||||
switch (status) {
|
||||
case ERROR:
|
||||
EventBus.getDefault().post(new MessageEvent(activity.getString(R.string.player_error_msg)));
|
||||
handleError(MediaPlayer.MEDIA_ERROR_UNKNOWN);
|
||||
break;
|
||||
case PAUSED:
|
||||
checkMediaInfoLoaded();
|
||||
onPositionObserverUpdate();
|
||||
updatePlayButtonShowsPlay(true);
|
||||
if (!PlaybackService.isCasting() && PlaybackService.getCurrentMediaType() == MediaType.VIDEO) {
|
||||
|
@ -288,7 +288,6 @@ public abstract class PlaybackController {
|
|||
}
|
||||
break;
|
||||
case PLAYING:
|
||||
checkMediaInfoLoaded();
|
||||
if (!PlaybackService.isCasting() && PlaybackService.getCurrentMediaType() == MediaType.VIDEO) {
|
||||
onAwaitingVideoSurface();
|
||||
setScreenOn(true);
|
||||
|
@ -296,26 +295,23 @@ public abstract class PlaybackController {
|
|||
updatePlayButtonShowsPlay(false);
|
||||
break;
|
||||
case PREPARING:
|
||||
checkMediaInfoLoaded();
|
||||
if (playbackService != null) {
|
||||
updatePlayButtonShowsPlay(!playbackService.isStartWhenPrepared());
|
||||
}
|
||||
break;
|
||||
case STOPPED:
|
||||
updatePlayButtonShowsPlay(true);
|
||||
break;
|
||||
case PREPARED:
|
||||
checkMediaInfoLoaded();
|
||||
updatePlayButtonShowsPlay(true);
|
||||
onPositionObserverUpdate();
|
||||
break;
|
||||
case SEEKING:
|
||||
onPositionObserverUpdate();
|
||||
break;
|
||||
case STOPPED: // Fall-through
|
||||
case INITIALIZED:
|
||||
checkMediaInfoLoaded();
|
||||
updatePlayButtonShowsPlay(true);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,6 @@ import de.danoeh.antennapod.core.storage.DBReader;
|
|||
import de.danoeh.antennapod.model.playback.RemoteMedia;
|
||||
import de.danoeh.antennapod.model.feed.FeedMedia;
|
||||
import de.danoeh.antennapod.model.playback.MediaType;
|
||||
import de.danoeh.antennapod.core.preferences.UserPreferences;
|
||||
import de.danoeh.antennapod.core.util.RewindAfterPauseUtils;
|
||||
import de.danoeh.antennapod.model.playback.Playable;
|
||||
|
||||
|
@ -367,8 +366,6 @@ public class RemotePSMP extends PlaybackServiceMediaPlayer {
|
|||
@Override
|
||||
public void resume() {
|
||||
try {
|
||||
// TODO see comment on prepare()
|
||||
// setVolume(UserPreferences.getLeftVolume(), UserPreferences.getRightVolume());
|
||||
if (playerStatus == PlayerStatus.PREPARED && media.getPosition() > 0) {
|
||||
int newPosition = RewindAfterPauseUtils.calculatePositionWithRewind(
|
||||
media.getPosition(),
|
||||
|
@ -405,9 +402,6 @@ public class RemotePSMP extends PlaybackServiceMediaPlayer {
|
|||
position,
|
||||
media.getLastPlayedTime());
|
||||
}
|
||||
// TODO We're not supporting user set stream volume yet, as we need to make a UI
|
||||
// that doesn't allow changing playback speed or have different values for left/right
|
||||
//setVolume(UserPreferences.getLeftVolume(), UserPreferences.getRightVolume());
|
||||
castMgr.loadMedia(remoteMedia, startWhenPrepared.get(), position);
|
||||
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
|
||||
Log.e(TAG, "Error loading media", e);
|
||||
|
@ -629,7 +623,7 @@ public class RemotePSMP extends PlaybackServiceMediaPlayer {
|
|||
if (shouldContinue) {
|
||||
nextMedia = callback.getNextInQueue(currentMedia);
|
||||
|
||||
boolean playNextEpisode = isPlaying && nextMedia != null && UserPreferences.isFollowQueue();
|
||||
boolean playNextEpisode = isPlaying && nextMedia != null;
|
||||
if (playNextEpisode) {
|
||||
Log.d(TAG, "Playback of next episode will start immediately.");
|
||||
} else if (nextMedia == null){
|
||||
|
|
Loading…
Reference in New Issue