Combine play and pause button into 1
detailed in https://github.com/danieloeh/AntennaPod/issues/574
This commit is contained in:
parent
9659c18d89
commit
e9ed796fd4
@ -284,18 +284,13 @@ public class PlaybackService extends Service {
|
|||||||
private void handleKeycode(int keycode) {
|
private void handleKeycode(int keycode) {
|
||||||
if (BuildConfig.DEBUG)
|
if (BuildConfig.DEBUG)
|
||||||
Log.d(TAG, "Handling keycode: " + keycode);
|
Log.d(TAG, "Handling keycode: " + keycode);
|
||||||
|
|
||||||
final PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo();
|
final PlaybackServiceMediaPlayer.PSMPInfo info = mediaPlayer.getPSMPInfo();
|
||||||
final PlayerStatus status = info.playerStatus;
|
final PlayerStatus status = info.playerStatus;
|
||||||
switch (keycode) {
|
switch (keycode) {
|
||||||
case KeyEvent.KEYCODE_HEADSETHOOK:
|
case KeyEvent.KEYCODE_HEADSETHOOK:
|
||||||
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
||||||
if (status == PlayerStatus.PLAYING) {
|
if (status == PlayerStatus.PLAYING) {
|
||||||
if (UserPreferences.isPersistNotify()) {
|
|
||||||
mediaPlayer.pause(false, true);
|
mediaPlayer.pause(false, true);
|
||||||
} else {
|
|
||||||
mediaPlayer.pause(true, true);
|
|
||||||
}
|
|
||||||
} else if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) {
|
} else if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) {
|
||||||
mediaPlayer.resume();
|
mediaPlayer.resume();
|
||||||
} else if (status == PlayerStatus.PREPARING) {
|
} else if (status == PlayerStatus.PREPARING) {
|
||||||
@ -315,11 +310,7 @@ public class PlaybackService extends Service {
|
|||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_MEDIA_PAUSE:
|
case KeyEvent.KEYCODE_MEDIA_PAUSE:
|
||||||
if (status == PlayerStatus.PLAYING) {
|
if (status == PlayerStatus.PLAYING) {
|
||||||
if (UserPreferences.isPersistNotify()) {
|
|
||||||
mediaPlayer.pause(false, true);
|
mediaPlayer.pause(false, true);
|
||||||
} else {
|
|
||||||
mediaPlayer.pause(true, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_MEDIA_NEXT:
|
case KeyEvent.KEYCODE_MEDIA_NEXT:
|
||||||
@ -333,7 +324,9 @@ public class PlaybackService extends Service {
|
|||||||
case KeyEvent.KEYCODE_MEDIA_STOP:
|
case KeyEvent.KEYCODE_MEDIA_STOP:
|
||||||
if (status == PlayerStatus.PLAYING) {
|
if (status == PlayerStatus.PLAYING) {
|
||||||
mediaPlayer.pause(true, true);
|
mediaPlayer.pause(true, true);
|
||||||
|
started = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
stopForeground(true); // gets rid of persistent notification
|
stopForeground(true); // gets rid of persistent notification
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -409,12 +402,8 @@ public class PlaybackService extends Service {
|
|||||||
taskManager.cancelPositionSaver();
|
taskManager.cancelPositionSaver();
|
||||||
saveCurrentPosition(false, 0);
|
saveCurrentPosition(false, 0);
|
||||||
taskManager.cancelWidgetUpdater();
|
taskManager.cancelWidgetUpdater();
|
||||||
if (UserPreferences.isPersistNotify() && android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
setupNotification(newInfo);
|
||||||
// do not remove notification on pause based on user pref and whether android version supports expanded notifications
|
|
||||||
} else {
|
|
||||||
// remove notifcation on pause
|
|
||||||
stopForeground(true);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case STOPPED:
|
case STOPPED:
|
||||||
@ -431,6 +420,7 @@ public class PlaybackService extends Service {
|
|||||||
taskManager.startPositionSaver();
|
taskManager.startPositionSaver();
|
||||||
taskManager.startWidgetUpdater();
|
taskManager.startWidgetUpdater();
|
||||||
setupNotification(newInfo);
|
setupNotification(newInfo);
|
||||||
|
started = true;
|
||||||
break;
|
break;
|
||||||
case ERROR:
|
case ERROR:
|
||||||
writePlaybackPreferencesNoMediaPlaying();
|
writePlaybackPreferencesNoMediaPlaying();
|
||||||
@ -734,8 +724,9 @@ public class PlaybackService extends Service {
|
|||||||
PlaybackServiceMediaPlayer.PSMPInfo newInfo = mediaPlayer.getPSMPInfo();
|
PlaybackServiceMediaPlayer.PSMPInfo newInfo = mediaPlayer.getPSMPInfo();
|
||||||
final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext());
|
final int smallIcon = ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext());
|
||||||
|
|
||||||
if (!isCancelled() && info.playerStatus == PlayerStatus.PLAYING
|
if (!isCancelled() &&
|
||||||
&& info.playable != null) {
|
started == true &&
|
||||||
|
info.playable != null) {
|
||||||
String contentText = info.playable.getFeedTitle();
|
String contentText = info.playable.getFeedTitle();
|
||||||
String contentTitle = info.playable.getEpisodeTitle();
|
String contentTitle = info.playable.getEpisodeTitle();
|
||||||
Notification notification = null;
|
Notification notification = null;
|
||||||
@ -775,14 +766,17 @@ public class PlaybackService extends Service {
|
|||||||
.setContentIntent(pIntent)
|
.setContentIntent(pIntent)
|
||||||
.setLargeIcon(icon)
|
.setLargeIcon(icon)
|
||||||
.setSmallIcon(smallIcon)
|
.setSmallIcon(smallIcon)
|
||||||
.setPriority(UserPreferences.getNotifyPriority()) // set notification priority
|
.setPriority(UserPreferences.getNotifyPriority()); // set notification priority
|
||||||
.addAction(android.R.drawable.ic_media_play, //play action
|
if(newInfo.playerStatus==PlayerStatus.PLAYING){
|
||||||
getString(R.string.play_label),
|
notificationBuilder.addAction(android.R.drawable.ic_media_pause, //pause action
|
||||||
playButtonPendingIntent)
|
|
||||||
.addAction(android.R.drawable.ic_media_pause, //pause action
|
|
||||||
getString(R.string.pause_label),
|
getString(R.string.pause_label),
|
||||||
pauseButtonPendingIntent)
|
pauseButtonPendingIntent);
|
||||||
.addAction(android.R.drawable.ic_menu_close_clear_cancel, // stop action
|
} else {
|
||||||
|
notificationBuilder.addAction(android.R.drawable.ic_media_play, //play action
|
||||||
|
getString(R.string.play_label),
|
||||||
|
playButtonPendingIntent);
|
||||||
|
}
|
||||||
|
notificationBuilder.addAction(android.R.drawable.ic_menu_close_clear_cancel, // stop action
|
||||||
getString(R.string.stop_label),
|
getString(R.string.stop_label),
|
||||||
stopButtonPendingIntent);
|
stopButtonPendingIntent);
|
||||||
notification = notificationBuilder.build();
|
notification = notificationBuilder.build();
|
||||||
@ -795,9 +789,7 @@ public class PlaybackService extends Service {
|
|||||||
.setSmallIcon(smallIcon);
|
.setSmallIcon(smallIcon);
|
||||||
notification = notificationBuilder.getNotification();
|
notification = notificationBuilder.getNotification();
|
||||||
}
|
}
|
||||||
if (newInfo.playerStatus == PlayerStatus.PLAYING) {
|
|
||||||
startForeground(NOTIFICATION_ID, notification);
|
startForeground(NOTIFICATION_ID, notification);
|
||||||
}
|
|
||||||
if (BuildConfig.DEBUG)
|
if (BuildConfig.DEBUG)
|
||||||
Log.d(TAG, "Notification set up");
|
Log.d(TAG, "Notification set up");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user