diff --git a/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java b/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java index 4efa84a8..9440743d 100644 --- a/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java +++ b/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioService.java @@ -487,11 +487,10 @@ private Notification buildNotification() { final MediaStyle style = new MediaStyle() .setMediaSession(mediaSession.getSessionToken()) .setShowActionsInCompactView(compactActionIndices); - if (config.androidNotificationOngoing) { - style.setShowCancelButton(true); - style.setCancelButtonIntent(buildMediaButtonPendingIntent(PlaybackStateCompat.ACTION_STOP)); - builder.setOngoing(true); - } + boolean isActuallyPlaying = this.isActuallyPlaying(); + style.setShowCancelButton(!isActuallyPlaying); + style.setCancelButtonIntent(buildMediaButtonPendingIntent(PlaybackStateCompat.ACTION_STOP)); + builder.setOngoing(isActuallyPlaying); builder.setStyle(style); return builder.build(); } diff --git a/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServiceConfig.java b/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServiceConfig.java index 1917989d..a742bcb6 100644 --- a/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServiceConfig.java +++ b/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServiceConfig.java @@ -17,7 +17,6 @@ public class AudioServiceConfig { private static final String KEY_ANDROID_NOTIFICATION_ICON = "androidNotificationIcon"; private static final String KEY_ANDROID_SHOW_NOTIFICATION_BADGE = "androidShowNotificationBadge"; private static final String KEY_ANDROID_NOTIFICATION_CLICK_STARTS_ACTIVITY = "androidNotificationClickStartsActivity"; - private static final String KEY_ANDROID_NOTIFICATION_ONGOING = "androidNotificationOngoing"; private static final String KEY_ANDROID_STOP_FOREGROUND_ON_PAUSE = "androidStopForegroundOnPause"; private static final String KEY_ART_DOWNSCALE_WIDTH = "artDownscaleWidth"; private static final String KEY_ART_DOWNSCALE_HEIGHT = "artDownscaleHeight"; @@ -33,7 +32,6 @@ public class AudioServiceConfig { public String androidNotificationIcon; public boolean androidShowNotificationBadge; public boolean androidNotificationClickStartsActivity; - public boolean androidNotificationOngoing; public boolean androidStopForegroundOnPause; public int artDownscaleWidth; public int artDownscaleHeight; @@ -50,7 +48,6 @@ public AudioServiceConfig(Context context) { androidNotificationIcon = preferences.getString(KEY_ANDROID_NOTIFICATION_ICON, "mipmap/ic_launcher"); androidShowNotificationBadge = preferences.getBoolean(KEY_ANDROID_SHOW_NOTIFICATION_BADGE, false); androidNotificationClickStartsActivity = preferences.getBoolean(KEY_ANDROID_NOTIFICATION_CLICK_STARTS_ACTIVITY, true); - androidNotificationOngoing = preferences.getBoolean(KEY_ANDROID_NOTIFICATION_ONGOING, false); androidStopForegroundOnPause = preferences.getBoolean(KEY_ANDROID_STOP_FOREGROUND_ON_PAUSE, true); artDownscaleWidth = preferences.getInt(KEY_ART_DOWNSCALE_WIDTH, -1); artDownscaleHeight = preferences.getInt(KEY_ART_DOWNSCALE_HEIGHT, -1); @@ -109,7 +106,6 @@ public void save() { .putString(KEY_ANDROID_NOTIFICATION_ICON, androidNotificationIcon) .putBoolean(KEY_ANDROID_SHOW_NOTIFICATION_BADGE, androidShowNotificationBadge) .putBoolean(KEY_ANDROID_NOTIFICATION_CLICK_STARTS_ACTIVITY, androidNotificationClickStartsActivity) - .putBoolean(KEY_ANDROID_NOTIFICATION_ONGOING, androidNotificationOngoing) .putBoolean(KEY_ANDROID_STOP_FOREGROUND_ON_PAUSE, androidStopForegroundOnPause) .putInt(KEY_ART_DOWNSCALE_WIDTH, artDownscaleWidth) .putInt(KEY_ART_DOWNSCALE_HEIGHT, artDownscaleHeight) diff --git a/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServicePlugin.java b/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServicePlugin.java index e4bc98c8..18b15c88 100644 --- a/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServicePlugin.java +++ b/audio_service/android/src/main/java/com/ryanheise/audioservice/AudioServicePlugin.java @@ -414,7 +414,6 @@ public void onMethodCall(MethodCall call, final Result result) { Map configMap = (Map)args.get("config"); AudioServiceConfig config = new AudioServiceConfig(context.getApplicationContext()); config.androidNotificationClickStartsActivity = (Boolean)configMap.get("androidNotificationClickStartsActivity"); - config.androidNotificationOngoing = (Boolean)configMap.get("androidNotificationOngoing"); config.androidResumeOnClick = (Boolean)configMap.get("androidResumeOnClick"); config.androidNotificationChannelId = (String)configMap.get("androidNotificationChannelId"); config.androidNotificationChannelName = (String)configMap.get("androidNotificationChannelName"); diff --git a/audio_service/example/lib/example_multiple_handlers.dart b/audio_service/example/lib/example_multiple_handlers.dart index 45eb3c3f..4d8acf90 100644 --- a/audio_service/example/lib/example_multiple_handlers.dart +++ b/audio_service/example/lib/example_multiple_handlers.dart @@ -47,7 +47,6 @@ Future main() async { config: const AudioServiceConfig( androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio', androidNotificationChannelName: 'Audio playback', - androidNotificationOngoing: true, ), ); runApp(MyApp()); diff --git a/audio_service/example/lib/example_playlist.dart b/audio_service/example/lib/example_playlist.dart index 09d0b4a3..42947cfe 100644 --- a/audio_service/example/lib/example_playlist.dart +++ b/audio_service/example/lib/example_playlist.dart @@ -26,7 +26,6 @@ Future main() async { config: const AudioServiceConfig( androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio', androidNotificationChannelName: 'Audio playback', - androidNotificationOngoing: true, ), ); runApp(MyApp()); diff --git a/audio_service/example/lib/main.dart b/audio_service/example/lib/main.dart index 69583141..1fb19f59 100644 --- a/audio_service/example/lib/main.dart +++ b/audio_service/example/lib/main.dart @@ -36,7 +36,6 @@ Future main() async { config: const AudioServiceConfig( androidNotificationChannelId: 'com.ryanheise.myapp.channel.audio', androidNotificationChannelName: 'Audio playback', - androidNotificationOngoing: true, ), ); runApp(MyApp()); diff --git a/audio_service/lib/audio_service.dart b/audio_service/lib/audio_service.dart index 1e812c3c..ce61c3e3 100644 --- a/audio_service/lib/audio_service.dart +++ b/audio_service/lib/audio_service.dart @@ -1228,7 +1228,6 @@ class AudioService { androidShowNotificationBadge: androidShowNotificationBadge, androidNotificationClickStartsActivity: androidNotificationClickStartsActivity, - androidNotificationOngoing: androidNotificationOngoing, androidStopForegroundOnPause: androidStopForegroundOnPause, artDownscaleWidth: androidArtDownscaleSize?.width.round(), artDownscaleHeight: androidArtDownscaleSize?.height.round(), @@ -3305,6 +3304,8 @@ class AudioServiceConfig { /// If you set this to true, [androidStopForegroundOnPause] must be true as well, /// otherwise this will not do anything, because when foreground service is active, /// it forces notification to be ongoing. + @Deprecated( + "Ongoing is now automatically set when your handler is ready and playing") final bool androidNotificationOngoing; /// Whether the Android service should switch to a lower priority state when @@ -3354,7 +3355,8 @@ class AudioServiceConfig { this.androidNotificationIcon = 'mipmap/ic_launcher', this.androidShowNotificationBadge = false, this.androidNotificationClickStartsActivity = true, - this.androidNotificationOngoing = false, + @Deprecated("Ongoing is now automatically set when your handler is ready and playing") + this.androidNotificationOngoing = false, this.androidStopForegroundOnPause = true, this.artDownscaleWidth, this.artDownscaleHeight, @@ -3362,11 +3364,7 @@ class AudioServiceConfig { this.rewindInterval = const Duration(seconds: 10), this.preloadArtwork = false, this.androidBrowsableRootExtras, - }) : assert((artDownscaleWidth != null) == (artDownscaleHeight != null)), - assert( - !androidNotificationOngoing || androidStopForegroundOnPause, - 'The androidNotificationOngoing will make no effect with androidStopForegroundOnPause set to false', - ); + }) : assert((artDownscaleWidth != null) == (artDownscaleHeight != null)); AudioServiceConfigMessage _toMessage() => AudioServiceConfigMessage( androidResumeOnClick: androidResumeOnClick, @@ -3379,7 +3377,7 @@ class AudioServiceConfig { androidShowNotificationBadge: androidShowNotificationBadge, androidNotificationClickStartsActivity: androidNotificationClickStartsActivity, - androidNotificationOngoing: androidNotificationOngoing, + androidNotificationOngoing: false, androidStopForegroundOnPause: androidStopForegroundOnPause, artDownscaleWidth: artDownscaleWidth, artDownscaleHeight: artDownscaleHeight, diff --git a/audio_service/test/data_classes_test.dart b/audio_service/test/data_classes_test.dart index 7b9583da..d73a45b2 100644 --- a/audio_service/test/data_classes_test.dart +++ b/audio_service/test/data_classes_test.dart @@ -357,18 +357,4 @@ void main() { ); }); }); - - group('$AudioServiceConfig $asciiSquare', () { - test('asserts proper notification ongoing config', () { - expect( - () { - AudioServiceConfig( - androidNotificationOngoing: true, - androidStopForegroundOnPause: false, - ); - }, - throwsAssertionError, - ); - }); - }); }