mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-06-09 03:52:12 +03:00
Improved cold start time from Doze
This commit is contained in:
parent
07553464e8
commit
5f3861b1ac
@ -143,6 +143,11 @@ public class MediaPlayerControllerImpl implements MediaPlayerController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public synchronized void preload()
|
||||||
|
{
|
||||||
|
MediaPlayerService.getInstance(context);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public synchronized void play(final int index)
|
public synchronized void play(final int index)
|
||||||
{
|
{
|
||||||
|
@ -65,12 +65,17 @@ public class MediaPlayerLifecycleSupport
|
|||||||
|
|
||||||
public void onCreate()
|
public void onCreate()
|
||||||
{
|
{
|
||||||
onCreate(false);
|
onCreate(false, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onCreate(final boolean autoPlay)
|
private void onCreate(final boolean autoPlay, final Runnable afterCreated)
|
||||||
{
|
{
|
||||||
if (created) return;
|
if (created)
|
||||||
|
{
|
||||||
|
if (afterCreated != null) afterCreated.run();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
registerHeadsetReceiver();
|
registerHeadsetReceiver();
|
||||||
|
|
||||||
// React to media buttons.
|
// React to media buttons.
|
||||||
@ -88,6 +93,8 @@ public class MediaPlayerLifecycleSupport
|
|||||||
context.registerReceiver(intentReceiver, commandFilter);
|
context.registerReceiver(intentReceiver, commandFilter);
|
||||||
|
|
||||||
mediaPlayerController.onCreate();
|
mediaPlayerController.onCreate();
|
||||||
|
if (autoPlay) mediaPlayerController.preload();
|
||||||
|
|
||||||
this.downloadQueueSerializer.deserializeDownloadQueue(new Consumer<State>() {
|
this.downloadQueueSerializer.deserializeDownloadQueue(new Consumer<State>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(State state) {
|
public void accept(State state) {
|
||||||
@ -96,6 +103,8 @@ public class MediaPlayerLifecycleSupport
|
|||||||
// Work-around: Serialize again, as the restore() method creates a serialization without current playing info.
|
// Work-around: Serialize again, as the restore() method creates a serialization without current playing info.
|
||||||
MediaPlayerLifecycleSupport.this.downloadQueueSerializer.serializeDownloadQueue(downloader.downloadList,
|
MediaPlayerLifecycleSupport.this.downloadQueueSerializer.serializeDownloadQueue(downloader.downloadList,
|
||||||
downloader.getCurrentPlayingIndex(), mediaPlayerController.getPlayerPosition());
|
downloader.getCurrentPlayingIndex(), mediaPlayerController.getPlayerPosition());
|
||||||
|
|
||||||
|
if (afterCreated != null) afterCreated.run();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -181,7 +190,7 @@ public class MediaPlayerLifecycleSupport
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int keyCode = event.getKeyCode();
|
final int keyCode = event.getKeyCode();
|
||||||
boolean autoStart = (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE ||
|
boolean autoStart = (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE ||
|
||||||
keyCode == KeyEvent.KEYCODE_MEDIA_PLAY ||
|
keyCode == KeyEvent.KEYCODE_MEDIA_PLAY ||
|
||||||
keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
|
keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
|
||||||
@ -189,8 +198,9 @@ public class MediaPlayerLifecycleSupport
|
|||||||
keyCode == KeyEvent.KEYCODE_MEDIA_NEXT);
|
keyCode == KeyEvent.KEYCODE_MEDIA_NEXT);
|
||||||
|
|
||||||
// We can receive intents (e.g. MediaButton) when everything is stopped, so we need to start
|
// We can receive intents (e.g. MediaButton) when everything is stopped, so we need to start
|
||||||
if (!created) onCreate(autoStart);
|
onCreate(autoStart, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
switch (keyCode)
|
switch (keyCode)
|
||||||
{
|
{
|
||||||
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
|
||||||
@ -241,6 +251,8 @@ public class MediaPlayerLifecycleSupport
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This receiver manages the intent that could come from other applications.
|
* This receiver manages the intent that could come from other applications.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user