aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de
diff options
context:
space:
mode:
authorChristian Schneppe <christian.schneppe@pix-art.de>2020-02-02 21:32:56 +0100
committerChristian Schneppe <christian.schneppe@pix-art.de>2020-02-02 21:32:56 +0100
commit64826a6fd9a8f013fe78fb12e6fc366adce7e122 (patch)
treef91ae47a6cba98020da26b9cc88b1b90d21915a8 /src/main/java/de
parent68d7b433d8ddaa8b684f3c7eb870a6acdbecf70a (diff)
show audio artist and title for audio files
Diffstat (limited to 'src/main/java/de')
-rw-r--r--src/main/java/de/pixart/messenger/entities/Message.java1
-rw-r--r--src/main/java/de/pixart/messenger/persistance/FileBackend.java29
-rw-r--r--src/main/java/de/pixart/messenger/services/AudioPlayer.java2
-rw-r--r--src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java33
4 files changed, 63 insertions, 2 deletions
diff --git a/src/main/java/de/pixart/messenger/entities/Message.java b/src/main/java/de/pixart/messenger/entities/Message.java
index 7d3334bba..b2297cd08 100644
--- a/src/main/java/de/pixart/messenger/entities/Message.java
+++ b/src/main/java/de/pixart/messenger/entities/Message.java
@@ -873,6 +873,7 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable
case 6:
fileParams.url = parseUrl(parts[0]);
fileParams.size = parseLong(parts[1]);
+ fileParams.runtime = parseInt(parts[4]);
fileParams.subject = parseString(parts[5]);
break;
diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
index c6d6448af..8293b9b98 100644
--- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java
+++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java
@@ -1155,7 +1155,7 @@ public class FileBackend {
//fall threw
}
} else if (audio) {
- body.append("|0|0|").append(getMediaRuntime(file));
+ body.append("|0|0|").append(getMediaRuntime(file)).append('|').append(getAudioTitleArtist(file));
} else if (vcard) {
body.append("|0|0|0|").append(getVCard(file));
} else if (apk) {
@@ -1182,6 +1182,33 @@ public class FileBackend {
}
}
+ private String getAudioTitleArtist(File file) {
+ try {
+ MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
+ mediaMetadataRetriever.setDataSource(file.toString());
+ StringBuilder builder = new StringBuilder();
+ String artist = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
+ String title = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
+ if (artist != null && artist.length() > 0) {
+ builder.append(artist);
+ }
+ if (title != null && title.length() > 0) {
+ builder.append(" - ");
+ builder.append(title);
+ }
+ try {
+ byte[] data = builder.toString().trim().getBytes("UTF-8");
+ return Base64.encodeToString(data, Base64.DEFAULT);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ return "";
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ return "";
+ }
+ }
+
private String getAPK(File file, Context context) {
String APKName;
final PackageManager pm = context.getPackageManager();
diff --git a/src/main/java/de/pixart/messenger/services/AudioPlayer.java b/src/main/java/de/pixart/messenger/services/AudioPlayer.java
index e41982be3..59e7416ea 100644
--- a/src/main/java/de/pixart/messenger/services/AudioPlayer.java
+++ b/src/main/java/de/pixart/messenger/services/AudioPlayer.java
@@ -12,6 +12,7 @@ import android.media.AudioManager;
import android.os.Build;
import android.os.Handler;
import android.os.PowerManager;
+import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
@@ -22,6 +23,7 @@ import android.widget.TextView;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
+import java.io.UnsupportedEncodingException;
import java.lang.ref.WeakReference;
import java.util.Locale;
import java.util.concurrent.ExecutorService;
diff --git a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
index 4228cd6cc..90582815e 100644
--- a/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
+++ b/src/main/java/de/pixart/messenger/ui/adapter/MessageAdapter.java
@@ -865,7 +865,7 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
}
private void displayAudioMessage(ViewHolder viewHolder, Message message, boolean darkBackground) {
- toggleWhisperInfo(viewHolder, message, false, darkBackground);
+ toggleWhisperInfo(viewHolder, message, showTitle(message), darkBackground);
viewHolder.image.setVisibility(View.GONE);
viewHolder.gifImage.setVisibility(View.GONE);
viewHolder.richlinkview.setVisibility(View.GONE);
@@ -877,6 +877,31 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
this.audioPlayer.init(audioPlayer, message);
}
+ private boolean showTitle(Message message) {
+ boolean show = false;
+ if (message.getFileParams().subject.length() != 0) {
+ try {
+ byte[] data = Base64.decode(message.getFileParams().subject, Base64.DEFAULT);
+ show = (new String(data, "UTF-8").length() != 0);
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ }
+ return show;
+ }
+
+ private String getTitle(Message message) {
+ if (message.getFileParams().subject.length() != 0) {
+ try {
+ byte[] data = Base64.decode(message.getFileParams().subject, Base64.DEFAULT);
+ return new String(data, "UTF-8");
+ } catch (UnsupportedEncodingException e) {
+ e.printStackTrace();
+ }
+ }
+ return "";
+ }
+
private void displayImageMessage(ViewHolder viewHolder, final Message message, final boolean darkBackground) {
toggleWhisperInfo(viewHolder, message, false, darkBackground);
viewHolder.download_button.setVisibility(View.GONE);
@@ -945,6 +970,12 @@ public class MessageAdapter extends ArrayAdapter<Message> implements CopyTextVie
private void toggleWhisperInfo(ViewHolder viewHolder, final Message message, final boolean includeBody, final boolean darkBackground) {
SpannableStringBuilder messageBody = new SpannableStringBuilder(replaceYoutube(activity.getApplicationContext(), message.getBody()));
+
+ final String mimeType = message.getMimeType();
+ if (mimeType != null && message.getMimeType().contains("audio")) {
+ messageBody.clear();
+ messageBody.append(getTitle(message));
+ }
Editable body;
if (darkBackground) {
viewHolder.messageBody.setTextAppearance(getContext(), R.style.TextAppearance_Conversations_Body1_OnDark);