Do not auto-enable sleep timer after skipping

This commit is contained in:
Martin Fietz 2016-12-04 21:42:03 +01:00
parent 17141db8a6
commit dc65f13f44
3 changed files with 22 additions and 18 deletions

View File

@ -612,7 +612,8 @@ public class PlaybackService extends MediaBrowserServiceCompat {
setupNotification(newInfo); setupNotification(newInfo);
started = true; started = true;
// set sleep timer if auto-enabled // set sleep timer if auto-enabled
if(SleepTimerPreferences.autoEnable() && !sleepTimerActive()) { if(newInfo.oldPlayerStatus != null && newInfo.oldPlayerStatus != PlayerStatus.SEEKING &&
SleepTimerPreferences.autoEnable() && !sleepTimerActive()) {
setSleepTimer(SleepTimerPreferences.timerMillis(), SleepTimerPreferences.shakeToReset(), setSleepTimer(SleepTimerPreferences.timerMillis(), SleepTimerPreferences.shakeToReset(),
SleepTimerPreferences.vibrate()); SleepTimerPreferences.vibrate());
} }

View File

@ -29,9 +29,10 @@ public abstract class PlaybackServiceMediaPlayer {
/** /**
* Return value of some PSMP methods if the method call failed. * Return value of some PSMP methods if the method call failed.
*/ */
public static final int INVALID_TIME = -1; static final int INVALID_TIME = -1;
protected volatile PlayerStatus playerStatus; volatile PlayerStatus oldPlayerStatus;
volatile PlayerStatus playerStatus;
/** /**
* A wifi-lock that is acquired if the media file is being streamed. * A wifi-lock that is acquired if the media file is being streamed.
@ -41,8 +42,8 @@ public abstract class PlaybackServiceMediaPlayer {
protected final PSMPCallback callback; protected final PSMPCallback callback;
protected final Context context; protected final Context context;
public PlaybackServiceMediaPlayer(@NonNull Context context, PlaybackServiceMediaPlayer(@NonNull Context context,
@NonNull PSMPCallback callback){ @NonNull PSMPCallback callback){
this.context = context; this.context = context;
this.callback = callback; this.callback = callback;
@ -204,7 +205,7 @@ public abstract class PlaybackServiceMediaPlayer {
* @return The PSMPInfo object. * @return The PSMPInfo object.
*/ */
public final synchronized PSMPInfo getPSMPInfo() { public final synchronized PSMPInfo getPSMPInfo() {
return new PSMPInfo(playerStatus, getPlayable()); return new PSMPInfo(oldPlayerStatus, playerStatus, getPlayable());
} }
/** /**
@ -275,7 +276,7 @@ public abstract class PlaybackServiceMediaPlayer {
*/ */
protected abstract boolean shouldLockWifi(); protected abstract boolean shouldLockWifi();
protected final synchronized void acquireWifiLockIfNecessary() { final synchronized void acquireWifiLockIfNecessary() {
if (shouldLockWifi()) { if (shouldLockWifi()) {
if (wifiLock == null) { if (wifiLock == null) {
wifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE)) wifiLock = ((WifiManager) context.getSystemService(Context.WIFI_SERVICE))
@ -286,7 +287,7 @@ public abstract class PlaybackServiceMediaPlayer {
} }
} }
protected final synchronized void releaseWifiLockIfNecessary() { final synchronized void releaseWifiLockIfNecessary() {
if (wifiLock != null && wifiLock.isHeld()) { if (wifiLock != null && wifiLock.isHeld()) {
wifiLock.release(); wifiLock.release();
} }
@ -307,29 +308,28 @@ public abstract class PlaybackServiceMediaPlayer {
* @param position The position to be set to the current Playable object in case playback started or paused. * @param position The position to be set to the current Playable object in case playback started or paused.
* Will be ignored if given the value of {@link #INVALID_TIME}. * Will be ignored if given the value of {@link #INVALID_TIME}.
*/ */
protected final synchronized void setPlayerStatus(@NonNull PlayerStatus newStatus, Playable newMedia, int position) { final synchronized void setPlayerStatus(@NonNull PlayerStatus newStatus, Playable newMedia, int position) {
Log.d(TAG, this.getClass().getSimpleName() + ": Setting player status to " + newStatus); Log.d(TAG, this.getClass().getSimpleName() + ": Setting player status to " + newStatus);
PlayerStatus oldStatus = playerStatus; this.oldPlayerStatus = playerStatus;
this.playerStatus = newStatus; this.playerStatus = newStatus;
setPlayable(newMedia); setPlayable(newMedia);
if (newMedia != null && newStatus != PlayerStatus.INDETERMINATE) { if (newMedia != null && newStatus != PlayerStatus.INDETERMINATE) {
if (oldStatus == PlayerStatus.PLAYING && newStatus != PlayerStatus.PLAYING) { if (oldPlayerStatus == PlayerStatus.PLAYING && newStatus != PlayerStatus.PLAYING) {
callback.onPlaybackPause(newMedia, position); callback.onPlaybackPause(newMedia, position);
} else if (oldStatus != PlayerStatus.PLAYING && newStatus == PlayerStatus.PLAYING) { } else if (oldPlayerStatus != PlayerStatus.PLAYING && newStatus == PlayerStatus.PLAYING) {
callback.onPlaybackStart(newMedia, position); callback.onPlaybackStart(newMedia, position);
} }
} }
callback.statusChanged(new PSMPInfo(playerStatus, getPlayable())); callback.statusChanged(new PSMPInfo(oldPlayerStatus, playerStatus, getPlayable()));
} }
/** /**
* @see #setPlayerStatus(PlayerStatus, Playable, int) * @see #setPlayerStatus(PlayerStatus, Playable, int)
*/ */
protected final void setPlayerStatus(@NonNull PlayerStatus newStatus, Playable newMedia) { final void setPlayerStatus(@NonNull PlayerStatus newStatus, Playable newMedia) {
setPlayerStatus(newStatus, newMedia, INVALID_TIME); setPlayerStatus(newStatus, newMedia, INVALID_TIME);
} }
@ -365,10 +365,12 @@ public abstract class PlaybackServiceMediaPlayer {
* Holds information about a PSMP object. * Holds information about a PSMP object.
*/ */
public static class PSMPInfo { public static class PSMPInfo {
public PlayerStatus oldPlayerStatus;
public PlayerStatus playerStatus; public PlayerStatus playerStatus;
public Playable playable; public Playable playable;
public PSMPInfo(PlayerStatus playerStatus, Playable playable) { PSMPInfo(PlayerStatus oldPlayerStatus, PlayerStatus playerStatus, Playable playable) {
this.oldPlayerStatus = oldPlayerStatus;
this.playerStatus = playerStatus; this.playerStatus = playerStatus;
this.playable = playable; this.playable = playable;
} }

View File

@ -131,7 +131,8 @@ public class PlaybackServiceFlavorHelper {
info = mediaPlayer.getPSMPInfo(); info = mediaPlayer.getPSMPInfo();
} }
if (info == null) { if (info == null) {
info = new PlaybackServiceMediaPlayer.PSMPInfo(PlayerStatus.STOPPED, null); info = new PlaybackServiceMediaPlayer.PSMPInfo(PlayerStatus.INDETERMINATE,
PlayerStatus.STOPPED, null);
} }
switchMediaPlayer(new LocalPSMP(context, callback.getMediaPlayerCallback()), switchMediaPlayer(new LocalPSMP(context, callback.getMediaPlayerCallback()),
info, true); info, true);
@ -166,7 +167,7 @@ public class PlaybackServiceFlavorHelper {
} }
} }
if (info == null) { if (info == null) {
info = new PlaybackServiceMediaPlayer.PSMPInfo(PlayerStatus.STOPPED, null); info = new PlaybackServiceMediaPlayer.PSMPInfo(PlayerStatus.INDETERMINATE, PlayerStatus.STOPPED, null);
} }
callback.sendNotificationBroadcast(PlaybackService.NOTIFICATION_TYPE_RELOAD, callback.sendNotificationBroadcast(PlaybackService.NOTIFICATION_TYPE_RELOAD,
PlaybackService.EXTRA_CODE_CAST); PlaybackService.EXTRA_CODE_CAST);