mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge
synced 2024-12-27 19:15:50 +01:00
Use AudioManager for Media Buttons
Switch from ACTION_MEDIA_BUTTON to all AudioManager Add mb_intents pref for audioplayer
This commit is contained in:
parent
932249f148
commit
739bd1b5a8
@ -48,6 +48,8 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
||||
int keyCode = -1;
|
||||
int volumeAdjust = AudioManager.ADJUST_LOWER;
|
||||
|
||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
|
||||
switch (musicCmd) {
|
||||
case NEXT:
|
||||
keyCode = KeyEvent.KEYCODE_MEDIA_NEXT;
|
||||
@ -74,7 +76,6 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
||||
// change default and fall through, :P
|
||||
volumeAdjust = AudioManager.ADJUST_RAISE;
|
||||
case VOLUMEDOWN:
|
||||
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
||||
audioManager.adjustStreamVolume(AudioManager.STREAM_MUSIC, volumeAdjust, 0);
|
||||
|
||||
final int volumeLevel = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
|
||||
@ -93,22 +94,30 @@ public class GBMusicControlReceiver extends BroadcastReceiver {
|
||||
LOG.debug("keypress: " + musicCmd.toString() + " sent to: " + audioPlayer);
|
||||
|
||||
long eventtime = SystemClock.uptimeMillis();
|
||||
|
||||
if (GBApplication.getPrefs().getBoolean("mb_intents", false)) {
|
||||
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
|
||||
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, keyCode, 0);
|
||||
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
|
||||
if (!"default".equals(audioPlayer)) {
|
||||
downIntent.setPackage(audioPlayer);
|
||||
}
|
||||
context.sendOrderedBroadcast(downIntent, null);
|
||||
|
||||
Intent downIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
|
||||
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, keyCode, 0);
|
||||
downIntent.putExtra(Intent.EXTRA_KEY_EVENT, downEvent);
|
||||
if (!"default".equals(audioPlayer)) {
|
||||
downIntent.setPackage(audioPlayer);
|
||||
}
|
||||
context.sendOrderedBroadcast(downIntent, null);
|
||||
Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
|
||||
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, keyCode, 0);
|
||||
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
|
||||
if (!"default".equals(audioPlayer)) {
|
||||
upIntent.setPackage(audioPlayer);
|
||||
}
|
||||
context.sendOrderedBroadcast(upIntent, null);
|
||||
} else {
|
||||
KeyEvent downEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_DOWN, keyCode, 0);
|
||||
audioManager.dispatchMediaKeyEvent(downEvent);
|
||||
|
||||
Intent upIntent = new Intent(Intent.ACTION_MEDIA_BUTTON, null);
|
||||
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, keyCode, 0);
|
||||
upIntent.putExtra(Intent.EXTRA_KEY_EVENT, upEvent);
|
||||
if (!"default".equals(audioPlayer)) {
|
||||
upIntent.setPackage(audioPlayer);
|
||||
KeyEvent upEvent = new KeyEvent(eventtime, eventtime, KeyEvent.ACTION_UP, keyCode, 0);
|
||||
audioManager.dispatchMediaKeyEvent(upEvent);
|
||||
}
|
||||
context.sendOrderedBroadcast(upIntent, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -203,6 +203,7 @@
|
||||
<string name="pref_title_general_autoconnectonbluetooth">Connect to Gadgetbridge device when Bluetooth is turned on</string>
|
||||
<string name="pref_title_general_autostartonboot">Start automatically</string>
|
||||
<string name="pref_title_general_autoreconnect">Reconnect automatically</string>
|
||||
<string name="pref_title_mb_intents">Broadcast Media Button Intents Directly</string>
|
||||
<string name="pref_title_audio_player">Preferred Audioplayer</string>
|
||||
<string name="pref_default">Default</string>
|
||||
<string name="pref_header_datetime">Date and Time</string>
|
||||
|
@ -34,6 +34,12 @@
|
||||
android:title="@string/pref_title_audio_player"
|
||||
android:summary="%s" />
|
||||
|
||||
<CheckBoxPreference
|
||||
android:layout="@layout/preference_checkbox"
|
||||
android:defaultValue="false"
|
||||
android:key="mb_intents"
|
||||
android:title="@string/pref_title_mb_intents" />
|
||||
|
||||
<PreferenceScreen android:title="@string/pref_title_theme">
|
||||
<ListPreference
|
||||
android:defaultValue="@string/pref_theme_value_light"
|
||||
|
Loading…
Reference in New Issue
Block a user