1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-12-25 10:05:49 +01:00

Pebble: Address the missing remarks of #807

- Separate the getAudioPlayer method
- Replace the println calls with proper LOG statements
This commit is contained in:
Daniele Gobbetti 2017-09-25 11:09:45 +02:00
parent 4d2cc8cfcb
commit c74ea64b70

View File

@ -76,22 +76,7 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
}
if (keyCode != -1) {
Prefs prefs = GBApplication.getPrefs();
String audioPlayer = prefs.getString("audio_player", "default");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
MediaSessionManager mediaSessionManager =
(MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
List<MediaController> controllers = mediaSessionManager.getActiveSessions(
new ComponentName(context, NotificationListener.class));
try {
MediaController controller = controllers.get(0);
audioPlayer = controller.getPackageName();
} catch (IndexOutOfBoundsException e) {
System.err.println("IndexOutOfBoundsException: " + e.getMessage());
}
}
String audioPlayer = getAudioPlayer(context);
LOG.debug("keypress: " + musicCmd.toString() + " sent to: " + audioPlayer);
@ -114,4 +99,23 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
context.sendOrderedBroadcast(upIntent, null);
}
}
private String getAudioPlayer(Context context) {
Prefs prefs = GBApplication.getPrefs();
String audioPlayer = prefs.getString("audio_player", "default");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
MediaSessionManager mediaSessionManager =
(MediaSessionManager) context.getSystemService(Context.MEDIA_SESSION_SERVICE);
List<MediaController> controllers = mediaSessionManager.getActiveSessions(
new ComponentName(context, NotificationListener.class));
try {
MediaController controller = controllers.get(0);
audioPlayer = controller.getPackageName();
} catch (IndexOutOfBoundsException e) {
LOG.error("IndexOutOfBoundsException: " + e.getMessage());
}
}
return audioPlayer;
}
}