diff options
Diffstat (limited to 'src/main/java/de/pixart/messenger/persistance')
-rw-r--r-- | src/main/java/de/pixart/messenger/persistance/FileBackend.java | 29 |
1 files changed, 28 insertions, 1 deletions
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(); |