diff --git a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverCallback.java b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverCallback.java index 6122f847..294e8dc8 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverCallback.java +++ b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverCallback.java @@ -30,7 +30,7 @@ import androidx.annotation.Nullable; import androidx.annotation.RequiresApi; -@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) +@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1) class MprisReceiverCallback extends MediaController.Callback { private static final String TAG = "MprisReceiver"; @@ -43,7 +43,6 @@ class MprisReceiverCallback extends MediaController.Callback { this.plugin = plugin; } - @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP) @Override public void onPlaybackStateChanged(PlaybackState state) { plugin.sendMetadata(player); @@ -54,4 +53,9 @@ class MprisReceiverCallback extends MediaController.Callback { plugin.sendMetadata(player); } + @Override + public void onAudioInfoChanged(MediaController.PlaybackInfo info) { + //Note: not called by all media players + plugin.sendMetadata(player); + } } diff --git a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlayer.java b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlayer.java index a138e860..8d7e6cad 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlayer.java +++ b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlayer.java @@ -147,9 +147,18 @@ class MprisReceiverPlayer { } int getVolume() { - if (controller.getPlaybackInfo() == null) - return 0; - return 100 * controller.getPlaybackInfo().getCurrentVolume() / controller.getPlaybackInfo().getMaxVolume(); + MediaController.PlaybackInfo info = controller.getPlaybackInfo(); + if (info == null) return 0; + return 100 * info.getCurrentVolume() / info.getMaxVolume(); + } + + void setVolume(int volume) { + MediaController.PlaybackInfo info = controller.getPlaybackInfo(); + if (info == null) return; + + //Use rounding for the volume, since most devices don't have a very large range + double unroundedVolume = info.getMaxVolume() * volume / 100.0 + 0.5; + controller.setVolumeTo((int) unroundedVolume, 0); } long getPosition() { diff --git a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java index 92107971..7f4b1cc7 100644 --- a/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/MprisReceiverPlugin/MprisReceiverPlugin.java @@ -134,6 +134,13 @@ public class MprisReceiverPlugin extends Plugin { player.setPosition(position); } + if (np.has("setVolume")) { + int volume = np.getInt("setVolume", 100); + player.setVolume(volume); + //Setting volume doesn't seem to always trigger the callback + sendMetadata(player); + } + if (np.has("action")) { String action = np.getString("action");