mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-17 04:00:39 +01:00
Minor fixes
This commit is contained in:
parent
02da3e79ba
commit
f6a41206b8
@ -25,6 +25,7 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.KeyEvent;
|
||||||
|
|
||||||
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
import org.moire.ultrasonic.service.DownloadServiceImpl;
|
||||||
import org.moire.ultrasonic.util.Util;
|
import org.moire.ultrasonic.util.Util;
|
||||||
@ -62,16 +63,36 @@ public class MediaButtonIntentReceiver extends BroadcastReceiver
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
context.startService(serviceIntent);
|
context.startService(serviceIntent);
|
||||||
|
}
|
||||||
|
catch (IllegalStateException exception)
|
||||||
|
{
|
||||||
|
Log.i(TAG, "MediaButtonIntentReceiver couldn't start DownloadServiceImpl because the application was in the background.");
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O)
|
||||||
|
{
|
||||||
|
KeyEvent keyEvent = (KeyEvent) event;
|
||||||
|
if (keyEvent.getAction() == KeyEvent.ACTION_DOWN && keyEvent.getRepeatCount() == 0)
|
||||||
|
{
|
||||||
|
int keyCode = keyEvent.getKeyCode();
|
||||||
|
if (keyCode == KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE ||
|
||||||
|
keyCode == KeyEvent.KEYCODE_HEADSETHOOK ||
|
||||||
|
keyCode == KeyEvent.KEYCODE_MEDIA_PLAY)
|
||||||
|
{
|
||||||
|
// TODO: The only time it is OK to start DownloadServiceImpl as a foreground service is when we now it will display its notification.
|
||||||
|
// When DownloadServiceImpl is refactored to a proper foreground service, this can be removed.
|
||||||
|
context.startForegroundService(serviceIntent);
|
||||||
|
Log.i(TAG, "MediaButtonIntentReceiver started DownloadServiceImpl as foreground service");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
if (isOrderedBroadcast())
|
if (isOrderedBroadcast())
|
||||||
{
|
{
|
||||||
abortBroadcast();
|
abortBroadcast();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (IllegalStateException exception)
|
|
||||||
{
|
|
||||||
Log.w(TAG, "MediaButtonIntentReceiver couldn't start DownloadServiceImpl because the application was in the background.");
|
|
||||||
}
|
|
||||||
catch (Exception x)
|
catch (Exception x)
|
||||||
{
|
{
|
||||||
// Ignored.
|
// Ignored.
|
||||||
|
@ -752,6 +752,7 @@ public class DownloadServiceImpl extends Service implements DownloadService
|
|||||||
if (tabInstance != null)
|
if (tabInstance != null)
|
||||||
{
|
{
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
|
clearRemoteControl();
|
||||||
isInForeground = false;
|
isInForeground = false;
|
||||||
tabInstance.hideNowPlaying();
|
tabInstance.hideNowPlaying();
|
||||||
}
|
}
|
||||||
@ -1277,6 +1278,7 @@ public class DownloadServiceImpl extends Service implements DownloadService
|
|||||||
if (tabInstance != null)
|
if (tabInstance != null)
|
||||||
{
|
{
|
||||||
stopForeground(true);
|
stopForeground(true);
|
||||||
|
clearRemoteControl();
|
||||||
isInForeground = false;
|
isInForeground = false;
|
||||||
tabInstance.hideNowPlaying();
|
tabInstance.hideNowPlaying();
|
||||||
}
|
}
|
||||||
|
@ -289,6 +289,7 @@ public class DownloadServiceLifecycleSupport
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.i(TAG, "Deserialized currentPlayingIndex: " + state.currentPlayingIndex + ", currentPlayingPosition: " + state.currentPlayingPosition);
|
Log.i(TAG, "Deserialized currentPlayingIndex: " + state.currentPlayingIndex + ", currentPlayingPosition: " + state.currentPlayingPosition);
|
||||||
|
// TODO: here the autoPlay = false creates problems when Ultrasonic is started by a Play MediaButton as the player won't start this way.
|
||||||
downloadService.restore(state.songs, state.currentPlayingIndex, state.currentPlayingPosition, false, false);
|
downloadService.restore(state.songs, state.currentPlayingIndex, state.currentPlayingPosition, false, false);
|
||||||
|
|
||||||
// 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.
|
||||||
@ -321,7 +322,11 @@ public class DownloadServiceLifecycleSupport
|
|||||||
downloadService.stop();
|
downloadService.stop();
|
||||||
break;
|
break;
|
||||||
case KeyEvent.KEYCODE_MEDIA_PLAY:
|
case KeyEvent.KEYCODE_MEDIA_PLAY:
|
||||||
if (downloadService.getPlayerState() != PlayerState.STARTED)
|
if (downloadService.getPlayerState() == PlayerState.IDLE)
|
||||||
|
{
|
||||||
|
downloadService.play();
|
||||||
|
}
|
||||||
|
else if (downloadService.getPlayerState() != PlayerState.STARTED)
|
||||||
{
|
{
|
||||||
downloadService.start();
|
downloadService.start();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user