Xiaomi: fix music volume command only increasing volume

Earlier Xiaomi devices would send either 0 or 100 for the requested
volume to indicate whether the app should increase or decrease the
phone's volume. Newer devices send the volume to change to, based on the
known current volume. We therefore need to check whether the device
increased or decreased the volume based on the current volume ourselves
in order to determine which event we want to fire.
This commit is contained in:
MrYoranimo 2024-04-11 15:53:10 +02:00
parent 35217aa405
commit d39f86f3c8
1 changed files with 7 additions and 2 deletions

View File

@ -85,13 +85,18 @@ public class XiaomiMusicService extends AbstractXiaomiService {
case BUTTON_NEXT:
deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.NEXT;
break;
case BUTTON_VOLUME:
if (music.getMediaKey().getVolume() > 0) {
case BUTTON_VOLUME: {
final int requestedVolume = music.getMediaKey().getVolume();
final int currentVolume = MediaManager.getPhoneVolume(getSupport().getContext());
if (requestedVolume > currentVolume) {
deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.VOLUMEUP;
} else {
deviceEventMusicControl.event = GBDeviceEventMusicControl.Event.VOLUMEDOWN;
}
break;
}
default:
LOG.warn("Unexpected media button key {}", music.getMediaKey().getKey());
return;