diff options
author | ByteHamster <info@bytehamster.com> | 2018-05-29 22:49:55 +0200 |
---|---|---|
committer | ByteHamster <info@bytehamster.com> | 2018-05-29 23:12:13 +0200 |
commit | 632906df071722e7d3d6b30faee09102dc1d4ef2 (patch) | |
tree | 31c753c6b0589ddc12581327bbb247a218dd1be7 /core/src/main/java/de | |
parent | fe92c98661e3b0817aed2c26dee258b0a572dd5e (diff) | |
download | AntennaPod-632906df071722e7d3d6b30faee09102dc1d4ef2.zip |
PlaybackService notification setup improvements
Diffstat (limited to 'core/src/main/java/de')
-rw-r--r-- | core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java | 53 |
1 files changed, 30 insertions, 23 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index be6cb346d..90df9871b 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -316,9 +316,6 @@ public class PlaybackService extends MediaBrowserServiceCompat { NotificationCompat.Builder notificationBuilder = createBasicNotification(); startForeground(NOTIFICATION_ID, notificationBuilder.build()); EventBus.getDefault().post(new ServiceEvent(ServiceEvent.Action.SERVICE_STARTED)); - - - setupNotification(Playable.PlayableUtils.createInstanceFromPreferences(getApplicationContext())); } private NotificationCompat.Builder createBasicNotification() { @@ -468,10 +465,13 @@ public class PlaybackService extends MediaBrowserServiceCompat { Log.d(TAG, "onStartCommand is a redelivered intent, calling stopForeground now."); stopForeground(true); } else { - if (keycode != -1) { Log.d(TAG, "Received media button event"); - handleKeycode(keycode, true); + boolean handled = handleKeycode(keycode, true); + if (!handled) { + stopSelf(); + return Service.START_NOT_STICKY; + } } else if (!flavorHelper.castDisconnect(castDisconnect) && playable != null) { started = true; boolean stream = intent.getBooleanExtra(EXTRA_SHOULD_STREAM, @@ -486,6 +486,7 @@ public class PlaybackService extends MediaBrowserServiceCompat { } mediaPlayer.playMediaObject(playable, stream, startWhenPrepared, prepareImmediately); } + setupNotification(playable); } return Service.START_NOT_STICKY; @@ -1215,38 +1216,44 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (notificationSetupThread != null) { notificationSetupThread.interrupt(); } + if (playable == null) { + Log.d(TAG, "setupNotification: playable is null"); + return; + } Runnable notificationSetupTask = new Runnable() { Bitmap icon = null; @Override public void run() { Log.d(TAG, "Starting background work"); - if (playable != null) { - int iconSize = getResources().getDimensionPixelSize( - android.R.dimen.notification_large_icon_width); - try { - icon = Glide.with(PlaybackService.this) - .load(playable.getImageLocation()) - .asBitmap() - .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) - .centerCrop() - .into(iconSize, iconSize) - .get(); - } catch (Throwable tr) { - Log.e(TAG, "Error loading the media icon for the notification", tr); - } + + if (mediaPlayer == null) { + Log.d(TAG, "notificationSetupTask: mediaPlayer is null"); + return; } + + int iconSize = getResources().getDimensionPixelSize( + android.R.dimen.notification_large_icon_width); + try { + icon = Glide.with(PlaybackService.this) + .load(playable.getImageLocation()) + .asBitmap() + .diskCacheStrategy(ApGlideSettings.AP_DISK_CACHE_STRATEGY) + .centerCrop() + .into(iconSize, iconSize) + .get(); + } catch (Throwable tr) { + Log.e(TAG, "Error loading the media icon for the notification", tr); + } + if (icon == null) { icon = BitmapFactory.decodeResource(getApplicationContext().getResources(), ClientConfig.playbackServiceCallbacks.getNotificationIconResource(getApplicationContext())); } - if (mediaPlayer == null) { - return; - } PlayerStatus playerStatus = mediaPlayer.getPlayerStatus(); - if (!Thread.currentThread().isInterrupted() && started && playable != null) { + if (!Thread.currentThread().isInterrupted() && started) { String contentText = playable.getEpisodeTitle(); String contentTitle = playable.getFeedTitle(); Notification notification; |