ensure the service continues to run in the event it takes a long time for the service to load the media to play, e.g.,

streaming over a slow network.
This commit is contained in:
orionlee 2019-02-27 14:59:31 -08:00
parent ab78c1d410
commit a3389490bb
1 changed files with 8 additions and 0 deletions

View File

@ -1932,6 +1932,14 @@ public class PlaybackService extends MediaBrowserServiceCompat {
try {
// Manage the started state of this service.
switch (state.getState()) {
case PlaybackStateCompat.STATE_CONNECTING:
// move the service to started, aka, making it foreground
// upon STATE_CONNECTING, i.e., in preparing to play a media.
// This is done so that in case the preparation takes a long time, e.g.,
// streaming over a slow network,
// the service won't be killed by the system prematurely.
moveServiceToStartedState(state);
break;
case PlaybackStateCompat.STATE_PLAYING:
moveServiceToStartedState(state);
break;