mirror of
https://github.com/ultrasonic/ultrasonic
synced 2025-02-17 04:00:39 +01:00
Fixed lost lockscreen controls when exiting the app
This commit is contained in:
parent
091374f922
commit
f5748d7dc0
@ -482,7 +482,7 @@ public class MainActivity extends SubsonicTabActivity
|
||||
private void exit()
|
||||
{
|
||||
lifecycleSupport.getValue().onDestroy();
|
||||
Util.unregisterMediaButtonEventReceiver(this);
|
||||
Util.unregisterMediaButtonEventReceiver(this, false);
|
||||
finish();
|
||||
}
|
||||
|
||||
|
@ -158,7 +158,7 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
||||
applyTheme();
|
||||
instance = this;
|
||||
|
||||
Util.registerMediaButtonEventReceiver(this);
|
||||
Util.registerMediaButtonEventReceiver(this, false);
|
||||
// Lifecycle support's constructor registers some event receivers so it should be created early
|
||||
lifecycleSupport.getValue().onCreate();
|
||||
|
||||
@ -195,7 +195,7 @@ public class SubsonicTabActivity extends ResultActivity implements OnClickListen
|
||||
@Override
|
||||
protected void onDestroy()
|
||||
{
|
||||
Util.unregisterMediaButtonEventReceiver(this);
|
||||
Util.unregisterMediaButtonEventReceiver(this, false);
|
||||
super.onDestroy();
|
||||
destroyed = true;
|
||||
nowPlayingView = null;
|
||||
|
@ -375,10 +375,10 @@ public class SettingsFragment extends PreferenceFragment
|
||||
private void setMediaButtonsEnabled(boolean enabled) {
|
||||
if (enabled) {
|
||||
lockScreenEnabled.setEnabled(true);
|
||||
Util.registerMediaButtonEventReceiver(getActivity());
|
||||
Util.registerMediaButtonEventReceiver(getActivity(), false);
|
||||
} else {
|
||||
lockScreenEnabled.setEnabled(false);
|
||||
Util.unregisterMediaButtonEventReceiver(getActivity());
|
||||
Util.unregisterMediaButtonEventReceiver(getActivity(), false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -65,7 +65,7 @@ public class BluetoothIntentReceiver extends BroadcastReceiver
|
||||
if (connected)
|
||||
{
|
||||
Log.i(TAG, "Connected to Bluetooth device, requesting media button focus.");
|
||||
Util.registerMediaButtonEventReceiver(context);
|
||||
Util.registerMediaButtonEventReceiver(context, false);
|
||||
}
|
||||
|
||||
if (disconnected)
|
||||
|
@ -168,7 +168,7 @@ public class LocalMediaPlayer
|
||||
wakeLock.setReferenceCounted(false);
|
||||
|
||||
audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
|
||||
Util.registerMediaButtonEventReceiver(context, true);
|
||||
setUpRemoteControlClient();
|
||||
|
||||
if (equalizerAvailable)
|
||||
@ -202,6 +202,11 @@ public class LocalMediaPlayer
|
||||
|
||||
try
|
||||
{
|
||||
Intent i = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
|
||||
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.getAudioSessionId());
|
||||
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName());
|
||||
context.sendBroadcast(i);
|
||||
|
||||
mediaPlayer.release();
|
||||
if (nextMediaPlayer != null)
|
||||
{
|
||||
@ -230,17 +235,14 @@ public class LocalMediaPlayer
|
||||
nextPlayingTask.cancel();
|
||||
}
|
||||
|
||||
Intent i = new Intent(AudioEffect.ACTION_CLOSE_AUDIO_EFFECT_CONTROL_SESSION);
|
||||
i.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, mediaPlayer.getAudioSessionId());
|
||||
i.putExtra(AudioEffect.EXTRA_PACKAGE_NAME, context.getPackageName());
|
||||
context.sendBroadcast(i);
|
||||
|
||||
audioManager.unregisterRemoteControlClient(remoteControlClient);
|
||||
clearRemoteControl();
|
||||
Util.unregisterMediaButtonEventReceiver(context, true);
|
||||
wakeLock.release();
|
||||
}
|
||||
catch (Throwable ignored)
|
||||
{
|
||||
Log.w(TAG, "LocalMediaPlayer onDestroy exception: ", ignored);
|
||||
}
|
||||
|
||||
Log.i(TAG, "LocalMediaPlayer destroyed");
|
||||
|
@ -74,7 +74,7 @@ public class MediaPlayerLifecycleSupport
|
||||
registerHeadsetReceiver();
|
||||
|
||||
// React to media buttons.
|
||||
Util.registerMediaButtonEventReceiver(context);
|
||||
Util.registerMediaButtonEventReceiver(context, true);
|
||||
|
||||
// Register the handler for outside intents.
|
||||
IntentFilter commandFilter = new IntentFilter();
|
||||
|
@ -96,6 +96,9 @@ public class Util extends DownloadActivity
|
||||
private static boolean pauseFocus;
|
||||
private static boolean lowerFocus;
|
||||
|
||||
private static boolean mediaButtonsRegisteredForUI;
|
||||
private static boolean mediaButtonsRegisteredForService;
|
||||
|
||||
private static final Map<Integer, Version> SERVER_REST_VERSIONS = new ConcurrentHashMap<Integer, Version>();
|
||||
|
||||
// Used by hexEncode()
|
||||
@ -890,19 +893,29 @@ public class Util extends DownloadActivity
|
||||
return Bitmap.createScaledBitmap(bitmap, size, getScaledHeight(bitmap, size), true);
|
||||
}
|
||||
|
||||
public static void registerMediaButtonEventReceiver(Context context)
|
||||
public static void registerMediaButtonEventReceiver(Context context, boolean isService)
|
||||
{
|
||||
if (getMediaButtonsPreference(context))
|
||||
{
|
||||
if (isService) mediaButtonsRegisteredForService = true;
|
||||
else mediaButtonsRegisteredForUI = true;
|
||||
|
||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
audioManager.registerMediaButtonEventReceiver(new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
public static void unregisterMediaButtonEventReceiver(Context context)
|
||||
public static void unregisterMediaButtonEventReceiver(Context context, boolean isService)
|
||||
{
|
||||
if (isService) mediaButtonsRegisteredForService = false;
|
||||
else mediaButtonsRegisteredForUI = false;
|
||||
|
||||
// Do not unregister while there is an active part of the app which needs the control
|
||||
if (mediaButtonsRegisteredForService || mediaButtonsRegisteredForUI) return;
|
||||
|
||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
audioManager.unregisterMediaButtonEventReceiver(new ComponentName(context.getPackageName(), MediaButtonIntentReceiver.class.getName()));
|
||||
Log.i(TAG, "MediaButtonEventReceiver unregistered.");
|
||||
}
|
||||
|
||||
public static MusicDirectory getSongsFromSearchResult(SearchResult searchResult)
|
||||
|
Loading…
x
Reference in New Issue
Block a user