Fixed widget if service is not running

This commit is contained in:
ByteHamster 2018-05-05 14:32:04 +02:00
parent 7107819a6a
commit 7a768e9809
1 changed files with 13 additions and 0 deletions

View File

@ -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.