Merge pull request #3571 from ByteHamster/hide-play-button-on-destroy

Updating notification play button in onDestroy
This commit is contained in:
H. Lehmann 2019-10-30 19:30:20 +01:00 committed by GitHub
commit e7367e218d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 28 additions and 8 deletions

View File

@ -326,6 +326,12 @@ public class PlaybackService extends MediaBrowserServiceCompat {
public void onDestroy() {
super.onDestroy();
Log.d(TAG, "Service is about to be destroyed");
if (notificationBuilder.getPlayerStatus() == PlayerStatus.PLAYING) {
notificationBuilder.setPlayerStatus(PlayerStatus.STOPPED);
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}
stateManager.stopForeground(!UserPreferences.isPersistNotify());
isRunning = false;
currentMediaType = MediaType.UNKNOWN;
@ -1197,7 +1203,10 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
PlayerStatus playerStatus = mediaPlayer.getPlayerStatus();
notificationBuilder.setMetadata(playable, mediaSession.getSessionToken(), playerStatus, isCasting);
notificationBuilder.setPlayable(playable);
notificationBuilder.setMediaSessionToken(mediaSession.getSessionToken());
notificationBuilder.setPlayerStatus(playerStatus);
notificationBuilder.setCasting(isCasting);
notificationBuilder.updatePosition(getCurrentPosition(), getCurrentPlaybackSpeed());
Log.d(TAG, "setupNotification: startForeground" + playerStatus);

View File

@ -46,16 +46,11 @@ public class PlaybackServiceNotificationBuilder {
this.context = context;
}
public void setMetadata(Playable playable, MediaSessionCompat.Token mediaSessionToken,
PlayerStatus playerStatus, boolean isCasting) {
public void setPlayable(Playable playable) {
if (playable != this.playable) {
clearCache();
}
this.playable = playable;
this.mediaSessionToken = mediaSessionToken;
this.playerStatus = playerStatus;
this.isCasting = isCasting;
}
private void clearCache() {
@ -63,7 +58,7 @@ public class PlaybackServiceNotificationBuilder {
this.position = null;
}
public void updatePosition(int position,float speed) {
public void updatePosition(int position, float speed) {
TimeSpeedConverter converter = new TimeSpeedConverter(speed);
this.position = Converter.getDurationStringLong(converter.convert(position));
}
@ -239,4 +234,20 @@ public class PlaybackServiceNotificationBuilder {
return PendingIntent.getService(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
}
}
public void setMediaSessionToken(MediaSessionCompat.Token mediaSessionToken) {
this.mediaSessionToken = mediaSessionToken;
}
public void setPlayerStatus(PlayerStatus playerStatus) {
this.playerStatus = playerStatus;
}
public void setCasting(boolean casting) {
isCasting = casting;
}
public PlayerStatus getPlayerStatus() {
return playerStatus;
}
}