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()
|
public void onCreate()
|
||||||
{
|
{
|
||||||
|
if (mediaPlayer != null)
|
||||||
|
{
|
||||||
|
mediaPlayer.release();
|
||||||
|
}
|
||||||
|
|
||||||
|
mediaPlayer = new MediaPlayer();
|
||||||
|
|
||||||
new Thread(new Runnable()
|
new Thread(new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
public void run()
|
public void run()
|
||||||
{
|
{
|
||||||
Thread.currentThread().setName("MediaPlayerThread");
|
Thread.currentThread().setName("MediaPlayerThread");
|
||||||
|
|
||||||
Looper.prepare();
|
Looper.prepare();
|
||||||
|
|
||||||
if (mediaPlayer != null)
|
|
||||||
{
|
|
||||||
mediaPlayer.release();
|
|
||||||
}
|
|
||||||
|
|
||||||
mediaPlayer = new MediaPlayer();
|
|
||||||
mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
|
mediaPlayer.setWakeMode(context, PowerManager.PARTIAL_WAKE_LOCK);
|
||||||
|
|
||||||
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener()
|
mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener()
|
||||||
|
|
|
@ -96,6 +96,9 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
|
||||||
{
|
{
|
||||||
externalStorageMonitor.onDestroy();
|
externalStorageMonitor.onDestroy();
|
||||||
context.stopService(new Intent(context, MediaPlayerService.class));
|
context.stopService(new Intent(context, MediaPlayerService.class));
|
||||||
|
shufflePlayBuffer.onDestroy();
|
||||||
|
downloader.onDestroy();
|
||||||
|
|
||||||
Log.i(TAG, "MediaPlayerControllerImpl destroyed");
|
Log.i(TAG, "MediaPlayerControllerImpl destroyed");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,29 +113,24 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
|
||||||
@Override
|
@Override
|
||||||
public void accept(MediaPlayerService mediaPlayerService) {
|
public void accept(MediaPlayerService mediaPlayerService) {
|
||||||
mediaPlayerService.play(currentPlayingIndex, autoPlayStart);
|
mediaPlayerService.play(currentPlayingIndex, autoPlayStart);
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (localMediaPlayer.currentPlaying != null)
|
if (localMediaPlayer.currentPlaying != null)
|
||||||
{
|
|
||||||
if (autoPlay && jukeboxMediaPlayer.getValue().isEnabled())
|
|
||||||
{
|
|
||||||
jukeboxMediaPlayer.getValue().skip(downloader.getCurrentPlayingIndex(), currentPlayingPosition / 1000);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (localMediaPlayer.currentPlaying.isCompleteFileAvailable())
|
|
||||||
{
|
{
|
||||||
MediaPlayerService.executeOnStartedMediaPlayerService(context, new Consumer<MediaPlayerService>() {
|
if (autoPlay && jukeboxMediaPlayer.getValue().isEnabled())
|
||||||
@Override
|
{
|
||||||
public void accept(MediaPlayerService mediaPlayerService) {
|
jukeboxMediaPlayer.getValue().skip(downloader.getCurrentPlayingIndex(), currentPlayingPosition / 1000);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (localMediaPlayer.currentPlaying.isCompleteFileAvailable())
|
||||||
|
{
|
||||||
localMediaPlayer.doPlay(localMediaPlayer.currentPlaying, currentPlayingPosition, autoPlay);
|
localMediaPlayer.doPlay(localMediaPlayer.currentPlaying, currentPlayingPosition, autoPlay);
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
}
|
}
|
||||||
|
autoPlayStart = false;
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
autoPlayStart = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -191,9 +191,9 @@ public class MediaPlayerService extends Service
|
||||||
instance = null;
|
instance = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
downloadQueueSerializer.serializeDownloadQueueNow(downloader.downloadList,
|
||||||
|
downloader.getCurrentPlayingIndex(), getPlayerPosition());
|
||||||
localMediaPlayer.onDestroy();
|
localMediaPlayer.onDestroy();
|
||||||
shufflePlayBuffer.onDestroy();
|
|
||||||
downloader.onDestroy();
|
|
||||||
} catch (Throwable ignored) {
|
} catch (Throwable ignored) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -205,7 +205,7 @@ public class MediaPlayerService extends Service
|
||||||
synchronized (instanceLock)
|
synchronized (instanceLock)
|
||||||
{
|
{
|
||||||
// currentPlaying could be changed from another thread in the meantime, so check again before stopping for good
|
// 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
|
else
|
||||||
{
|
{
|
||||||
|
setCurrentPlaying(index);
|
||||||
|
|
||||||
if (start)
|
if (start)
|
||||||
{
|
{
|
||||||
if (jukeboxMediaPlayer.getValue().isEnabled())
|
if (jukeboxMediaPlayer.getValue().isEnabled())
|
||||||
|
|
Loading…
Reference in New Issue