Fixed widget if service is not running
This commit is contained in:
parent
7107819a6a
commit
7a768e9809
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue