Fixed foreground service stop and start
Fixed play on restore
This commit is contained in:
parent
bd77c2a851
commit
fdc1748f8a
|
@ -119,21 +119,20 @@ public class LocalMediaPlayer
|
|||
|
||||
public void onCreate()
|
||||
{
|
||||
new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Thread.currentThread().setName("MediaPlayerThread");
|
||||
|
||||
Looper.prepare();
|
||||
|
||||
if (mediaPlayer != null)
|
||||
{
|
||||
mediaPlayer.release();
|
||||
}
|
||||
|
||||
mediaPlayer = new MediaPlayer();
|
||||
|
||||
new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
{
|
||||
Thread.currentThread().setName("MediaPlayerThread");
|
||||
Looper.prepare();
|
||||
mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
|
||||
|
||||
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener()
|
||||
|
|
|
@ -96,6 +96,9 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
|
|||
{
|
||||
externalStorageMonitor.onDestroy();
|
||||
context.stopService(new Intent(context, MediaPlayerService.class));
|
||||
shufflePlayBuffer.onDestroy();
|
||||
downloader.onDestroy();
|
||||
|
||||
Log.i(TAG, "MediaPlayerControllerImpl destroyed");
|
||||
}
|
||||
|
||||
|
@ -110,8 +113,6 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
|
|||
@Override
|
||||
public void accept(MediaPlayerService mediaPlayerService) {
|
||||
mediaPlayerService.play(currentPlayingIndex, autoPlayStart);
|
||||
}
|
||||
});
|
||||
|
||||
if (localMediaPlayer.currentPlaying != null)
|
||||
{
|
||||
|
@ -123,17 +124,14 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
|
|||
{
|
||||
if (localMediaPlayer.currentPlaying.isCompleteFileAvailable())
|
||||
{
|
||||
MediaPlayerService.executeOnStartedMediaPlayerService(context, new Consumer<MediaPlayerService>() {
|
||||
@Override
|
||||
public void accept(MediaPlayerService mediaPlayerService) {
|
||||
localMediaPlayer.doPlay(localMediaPlayer.currentPlaying, currentPlayingPosition, autoPlay);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
autoPlayStart = false;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -191,9 +191,9 @@ public class MediaPlayerService extends Service
|
|||
instance = null;
|
||||
|
||||
try {
|
||||
downloadQueueSerializer.serializeDownloadQueueNow(downloader.downloadList,
|
||||
downloader.getCurrentPlayingIndex(), getPlayerPosition());
|
||||
localMediaPlayer.onDestroy();
|
||||
shufflePlayBuffer.onDestroy();
|
||||
downloader.onDestroy();
|
||||
} catch (Throwable ignored) {
|
||||
}
|
||||
|
||||
|
@ -205,7 +205,7 @@ public class MediaPlayerService extends Service
|
|||
synchronized (instanceLock)
|
||||
{
|
||||
// currentPlaying could be changed from another thread in the meantime, so check again before stopping for good
|
||||
if (localMediaPlayer.currentPlaying == null) stopSelf();
|
||||
if (localMediaPlayer.currentPlaying == null || localMediaPlayer.playerState == STOPPED) stopSelf();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -385,6 +385,8 @@ public class MediaPlayerService extends Service
|
|||
}
|
||||
else
|
||||
{
|
||||
setCurrentPlaying(index);
|
||||
|
||||
if (start)
|
||||
{
|
||||
if (jukeboxMediaPlayer.getValue().isEnabled())
|
||||
|
|
Loading…
Reference in New Issue