From 7a768e9809dafc7e6f5944e26ebf2f1cb0e786aa Mon Sep 17 00:00:00 2001 From: ByteHamster Date: Sat, 5 May 2018 14:32:04 +0200 Subject: [PATCH] Fixed widget if service is not running --- .../core/service/playback/PlaybackService.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) 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 9643b9cd3..dc67c0758 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 @@ -515,6 +515,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { } else if (status == PlayerStatus.INITIALIZED) { mediaPlayer.setStartWhenPrepared(true); mediaPlayer.prepare(); + } else if (mediaPlayer.getPlayable() == null) { + startPlayingFromPreferences(); } return true; case KeyEvent.KEYCODE_MEDIA_PLAY: @@ -523,6 +525,8 @@ public class PlaybackService extends MediaBrowserServiceCompat { } else if (status == PlayerStatus.INITIALIZED) { mediaPlayer.setStartWhenPrepared(true); mediaPlayer.prepare(); + } else if (mediaPlayer.getPlayable() == null) { + startPlayingFromPreferences(); } return true; case KeyEvent.KEYCODE_MEDIA_PAUSE: @@ -576,6 +580,15 @@ public class PlaybackService extends MediaBrowserServiceCompat { return false; } + private void startPlayingFromPreferences() { + Playable playable = Playable.PlayableUtils.createInstanceFromPreferences(getApplicationContext()); + if (playable != null) { + mediaPlayer.playMediaObject(playable, false, true, true); + started = true; + PlaybackService.this.updateMediaSessionMetadata(playable); + } + } + /** * Called by a mediaplayer Activity as soon as it has prepared its * mediaplayer.