2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-30 21:55:10 +00:00

Add support to deal with album arts sent by mpris plugin.

We should probably look into resizing the album art according
 to the DPI of the device.
This commit is contained in:
Pinak Ahuja
2016-06-16 10:35:15 +02:00
parent 082de423c0
commit 24c404400f
3 changed files with 31 additions and 1 deletions

View File

@@ -20,6 +20,11 @@
android:id="@+id/no_players" android:id="@+id/no_players"
android:layout_gravity="center_horizontal" /> android:layout_gravity="center_horizontal" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/artImageView" />
<Spinner <Spinner
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"

View File

@@ -21,6 +21,8 @@
package org.kde.kdeconnect.Plugins.MprisPlugin; package org.kde.kdeconnect.Plugins.MprisPlugin;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
@@ -33,6 +35,7 @@ import android.view.View;
import android.widget.AdapterView; import android.widget.AdapterView;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.ImageButton; import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.SeekBar; import android.widget.SeekBar;
import android.widget.Spinner; import android.widget.Spinner;
import android.widget.TextView; import android.widget.TextView;
@@ -93,6 +96,13 @@ public class MprisActivity extends ActionBarActivity {
TextView nowPlaying = (TextView) findViewById(R.id.now_playing_textview); TextView nowPlaying = (TextView) findViewById(R.id.now_playing_textview);
if (!nowPlaying.getText().toString().equals(song)) { if (!nowPlaying.getText().toString().equals(song)) {
nowPlaying.setText(song); nowPlaying.setText(song);
Bitmap currentArt = mpris.getCurrentArt();
ImageView artView = (ImageView) findViewById(R.id.artImageView);
if (currentArt != null) {
artView.setImageBitmap(currentArt);
}
} }
if (mpris.getLength() > -1 && mpris.getPosition() > -1 && !"spotify".equals(mpris.getPlayer().toLowerCase())) { if (mpris.getLength() > -1 && mpris.getPosition() > -1 && !"spotify".equals(mpris.getPlayer().toLowerCase())) {

View File

@@ -22,10 +22,13 @@ package org.kde.kdeconnect.Plugins.MprisPlugin;
import android.app.Activity; import android.app.Activity;
import android.content.Intent; import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.Handler; import android.os.Handler;
import android.os.Message; import android.os.Message;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.util.Base64;
import android.util.Log; import android.util.Log;
import org.kde.kdeconnect.NetworkPackage; import org.kde.kdeconnect.NetworkPackage;
@@ -35,6 +38,8 @@ import org.kde.kdeconnect_tp.R;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import io.netty.handler.codec.base64.Base64Decoder;
public class MprisPlugin extends Plugin { public class MprisPlugin extends Plugin {
public final static String PACKAGE_TYPE_MPRIS = "kdeconnect.mpris"; public final static String PACKAGE_TYPE_MPRIS = "kdeconnect.mpris";
@@ -43,6 +48,7 @@ public class MprisPlugin extends Plugin {
private String player = ""; private String player = "";
private boolean playing = false; private boolean playing = false;
private String currentSong = ""; private String currentSong = "";
private Bitmap currentArt;
private int volume = 50; private int volume = 50;
private long length = -1; private long length = -1;
private long lastPosition; private long lastPosition;
@@ -120,7 +126,8 @@ public class MprisPlugin extends Plugin {
@Override @Override
public boolean onPackageReceived(NetworkPackage np) { public boolean onPackageReceived(NetworkPackage np) {
if (np.has("nowPlaying") || np.has("volume") || np.has("isPlaying") || np.has("length") || np.has("pos")) { if (np.has("nowPlaying") || np.has("volume") || np.has("isPlaying") || np.has("length") ||
np.has("pos") || np.has("artImage")) {
if (np.getString("player").equals(player)) { if (np.getString("player").equals(player)) {
currentSong = np.getString("nowPlaying", currentSong); currentSong = np.getString("nowPlaying", currentSong);
volume = np.getInt("volume", volume); volume = np.getInt("volume", volume);
@@ -129,6 +136,11 @@ public class MprisPlugin extends Plugin {
lastPosition = np.getLong("pos", lastPosition); lastPosition = np.getLong("pos", lastPosition);
lastPositionTime = System.currentTimeMillis(); lastPositionTime = System.currentTimeMillis();
} }
if (np.has("artImage")) {
String base64Image = np.getString("artImage");
byte[] decodedBytes = Base64.decode(base64Image, 0);
currentArt = BitmapFactory.decodeByteArray(decodedBytes, 0, decodedBytes.length);
}
playing = np.getBoolean("isPlaying", playing); playing = np.getBoolean("isPlaying", playing);
for (String key : playerStatusUpdated.keySet()) { for (String key : playerStatusUpdated.keySet()) {
try { try {
@@ -208,6 +220,7 @@ public class MprisPlugin extends Plugin {
if (player == null || player.equals(this.player)) return; if (player == null || player.equals(this.player)) return;
this.player = player; this.player = player;
currentSong = ""; currentSong = "";
currentArt = null;
volume = 50; volume = 50;
playing = false; playing = false;
for (String key : playerStatusUpdated.keySet()) { for (String key : playerStatusUpdated.keySet()) {
@@ -230,6 +243,8 @@ public class MprisPlugin extends Plugin {
return currentSong; return currentSong;
} }
public Bitmap getCurrentArt() { return currentArt; }
public String getPlayer() { public String getPlayer() {
return player; return player;
} }