From 2f26fa51885c24634cc898e654563ae16eb3ae3b Mon Sep 17 00:00:00 2001 From: Maksim Krylosov Date: Tue, 29 Oct 2013 19:44:32 +0100 Subject: [PATCH] Added rewind and fast-forward buttons to MPRIS controls --- .../Plugins/MprisPlugin/MprisActivity.java | 30 ++++++++++++++++++ .../Plugins/MprisPlugin/MprisPlugin.java | 7 +++++ src/main/res/layout/mpris_control.xml | 31 ++++++++++++++----- src/main/res/values/strings.xml | 2 ++ 4 files changed, 63 insertions(+), 7 deletions(-) diff --git a/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java b/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java index 6389255c..81fce878 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java @@ -187,6 +187,36 @@ public class MprisActivity extends Activity { } }); + findViewById(R.id.rew_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { + @Override + public void onServiceStart(BackgroundService service) { + Device device = service.getDevice(deviceId); + MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris"); + if (mpris == null) return; + mpris.Seek(-10000000); // -10 seconds. TODO: plugin settings UI? + } + }); + } + }); + + findViewById(R.id.ff_button).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { + @Override + public void onServiceStart(BackgroundService service) { + Device device = service.getDevice(deviceId); + MprisPlugin mpris = (MprisPlugin)device.getPlugin("plugin_mpris"); + if (mpris == null) return; + mpris.Seek(10000000); // 10 seconds. TODO: plugin settings UI? + } + }); + } + }); + findViewById(R.id.next_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java b/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java index c9b97934..4ad57bea 100644 --- a/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java +++ b/src/main/java/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java @@ -84,6 +84,13 @@ public class MprisPlugin extends Plugin { device.sendPackage(np); } + public void Seek(int offset) { + NetworkPackage np = new NetworkPackage(NetworkPackage.PACKAGE_TYPE_MPRIS); + np.set("player",player); + np.set("Seek",offset); + device.sendPackage(np); + } + @Override public boolean onPackageReceived(NetworkPackage np) { if (!np.getType().equals(NetworkPackage.PACKAGE_TYPE_MPRIS)) return false; diff --git a/src/main/res/layout/mpris_control.xml b/src/main/res/layout/mpris_control.xml index 69e89c82..92a6a3d2 100644 --- a/src/main/res/layout/mpris_control.xml +++ b/src/main/res/layout/mpris_control.xml @@ -37,7 +37,7 @@ @@ -45,19 +45,36 @@ android:layout_width="match_parent" android:layout_height="fill_parent" android:id="@+id/prev_button" - android:src="@android:drawable/ic_media_rew" + android:src="@android:drawable/ic_media_previous" android:contentDescription="@string/mpris_previous" - android:layout_weight="0.5" + android:layout_weight="0.25" + /> + + + + @@ -107,4 +124,4 @@ android:src="@android:drawable/ic_media_stop" android:layout_gravity="center"/> --> - \ No newline at end of file + diff --git a/src/main/res/values/strings.xml b/src/main/res/values/strings.xml index 7dc5a994..175487c2 100644 --- a/src/main/res/values/strings.xml +++ b/src/main/res/values/strings.xml @@ -50,6 +50,8 @@ KDE Connect Settings Play Previous + Rewind + Fast-forward Next Volume Share To...