Fixed foreground service stop and start

Fixed play on restore
This commit is contained in:
Nite 2020-06-29 14:44:19 +02:00
parent bd77c2a851
commit fdc1748f8a
No known key found for this signature in database
GPG Key ID: 1D1AD59B1C6386C1
3 changed files with 27 additions and 28 deletions

View File

@ -119,21 +119,20 @@ public class LocalMediaPlayer
public void onCreate()
{
if (mediaPlayer != null)
{
mediaPlayer.release();
}
mediaPlayer = new MediaPlayer();
new Thread(new Runnable()
{
@Override
public void run()
{
Thread.currentThread().setName("MediaPlayerThread");
Looper.prepare();
if (mediaPlayer != null)
{
mediaPlayer.release();
}
mediaPlayer = new MediaPlayer();
mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener()

View File

@ -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,29 +113,24 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
@Override
public void accept(MediaPlayerService mediaPlayerService) {
mediaPlayerService.play(currentPlayingIndex, autoPlayStart);
}
});
if (localMediaPlayer.currentPlaying != null)
{
if (autoPlay && jukeboxMediaPlayer.getValue().isEnabled())
{
jukeboxMediaPlayer.getValue().skip(downloader.getCurrentPlayingIndex(), currentPlayingPosition / 1000);
}
else
{
if (localMediaPlayer.currentPlaying.isCompleteFileAvailable())
if (localMediaPlayer.currentPlaying != null)
{
MediaPlayerService.executeOnStartedMediaPlayerService(context, new Consumer<MediaPlayerService>() {
@Override
public void accept(MediaPlayerService mediaPlayerService) {
if (autoPlay && jukeboxMediaPlayer.getValue().isEnabled())
{
jukeboxMediaPlayer.getValue().skip(downloader.getCurrentPlayingIndex(), currentPlayingPosition / 1000);
}
else
{
if (localMediaPlayer.currentPlaying.isCompleteFileAvailable())
{
localMediaPlayer.doPlay(localMediaPlayer.currentPlaying, currentPlayingPosition, autoPlay);
}
});
}
}
autoPlayStart = false;
}
}
autoPlayStart = false;
});
}
}

View File

@ -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())