mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 06:05:12 +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:
@@ -20,6 +20,11 @@
|
||||
android:id="@+id/no_players"
|
||||
android:layout_gravity="center_horizontal" />
|
||||
|
||||
<ImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:id="@+id/artImageView" />
|
||||
|
||||
<Spinner
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
@@ -21,6 +21,8 @@
|
||||
package org.kde.kdeconnect.Plugins.MprisPlugin;
|
||||
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
@@ -33,6 +35,7 @@ import android.view.View;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.SeekBar;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
@@ -93,6 +96,13 @@ public class MprisActivity extends ActionBarActivity {
|
||||
TextView nowPlaying = (TextView) findViewById(R.id.now_playing_textview);
|
||||
if (!nowPlaying.getText().toString().equals(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())) {
|
||||
|
@@ -22,10 +22,13 @@ package org.kde.kdeconnect.Plugins.MprisPlugin;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Handler;
|
||||
import android.os.Message;
|
||||
import android.support.v4.content.ContextCompat;
|
||||
import android.util.Base64;
|
||||
import android.util.Log;
|
||||
|
||||
import org.kde.kdeconnect.NetworkPackage;
|
||||
@@ -35,6 +38,8 @@ import org.kde.kdeconnect_tp.R;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
|
||||
import io.netty.handler.codec.base64.Base64Decoder;
|
||||
|
||||
public class MprisPlugin extends Plugin {
|
||||
|
||||
public final static String PACKAGE_TYPE_MPRIS = "kdeconnect.mpris";
|
||||
@@ -43,6 +48,7 @@ public class MprisPlugin extends Plugin {
|
||||
private String player = "";
|
||||
private boolean playing = false;
|
||||
private String currentSong = "";
|
||||
private Bitmap currentArt;
|
||||
private int volume = 50;
|
||||
private long length = -1;
|
||||
private long lastPosition;
|
||||
@@ -120,7 +126,8 @@ public class MprisPlugin extends Plugin {
|
||||
@Override
|
||||
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)) {
|
||||
currentSong = np.getString("nowPlaying", currentSong);
|
||||
volume = np.getInt("volume", volume);
|
||||
@@ -129,6 +136,11 @@ public class MprisPlugin extends Plugin {
|
||||
lastPosition = np.getLong("pos", lastPosition);
|
||||
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);
|
||||
for (String key : playerStatusUpdated.keySet()) {
|
||||
try {
|
||||
@@ -208,6 +220,7 @@ public class MprisPlugin extends Plugin {
|
||||
if (player == null || player.equals(this.player)) return;
|
||||
this.player = player;
|
||||
currentSong = "";
|
||||
currentArt = null;
|
||||
volume = 50;
|
||||
playing = false;
|
||||
for (String key : playerStatusUpdated.keySet()) {
|
||||
@@ -230,6 +243,8 @@ public class MprisPlugin extends Plugin {
|
||||
return currentSong;
|
||||
}
|
||||
|
||||
public Bitmap getCurrentArt() { return currentArt; }
|
||||
|
||||
public String getPlayer() {
|
||||
return player;
|
||||
}
|
||||
|
Reference in New Issue
Block a user