Fixed wired headset handling

Fixed MediaPlayer start timeout for slow phones
This commit is contained in:
Nite 2020-07-02 17:20:06 +02:00
parent 60250a42a9
commit 091374f922
No known key found for this signature in database
GPG Key ID: 1D1AD59B1C6386C1
2 changed files with 8 additions and 1 deletions

View File

@ -184,6 +184,7 @@ public class MediaPlayerLifecycleSupport
int keyCode = event.getKeyCode();
boolean autoStart = (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE ||
keyCode == KeyEvent.KEYCODE_MEDIA_PLAY ||
keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
keyCode == KeyEvent.KEYCODE_MEDIA_PREVIOUS ||
keyCode == KeyEvent.KEYCODE_MEDIA_NEXT);

View File

@ -82,7 +82,7 @@ public class MediaPlayerService extends Service
public static MediaPlayerService getInstance(Context context)
{
synchronized (instanceLock) {
for (int i = 0; i < 5; i++) {
for (int i = 0; i < 20; i++) {
if (instance != null) return instance;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
@ -113,6 +113,12 @@ public class MediaPlayerService extends Service
public void run()
{
MediaPlayerService instance = getInstance(context);
if (instance == null)
{
Log.e(TAG, "ExecuteOnStartedMediaPlayerService failed to get a MediaPlayerService instance!");
return;
}
taskToExecute.accept(instance);
}
};