From 3c3c645c68552c1c074650ce370a720e67c9ecf0 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Mon, 3 Feb 2020 21:46:26 +0100 Subject: update MetaDataExtractor --- .../pixart/messenger/persistance/FileBackend.java | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'src/main/java/de/pixart') diff --git a/src/main/java/de/pixart/messenger/persistance/FileBackend.java b/src/main/java/de/pixart/messenger/persistance/FileBackend.java index 8293b9b98..08dc746c1 100644 --- a/src/main/java/de/pixart/messenger/persistance/FileBackend.java +++ b/src/main/java/de/pixart/messenger/persistance/FileBackend.java @@ -1183,17 +1183,30 @@ public class FileBackend { } private String getAudioTitleArtist(File file) { + String artist; + String title; + StringBuilder builder = new StringBuilder(); 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); + artist = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); + if (artist == null) { + artist = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUMARTIST); + } + if (artist == null) { + artist = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_COMPOSER); + } + title = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); + mediaMetadataRetriever.release(); + boolean separator = false; if (artist != null && artist.length() > 0) { builder.append(artist); + separator = true; } if (title != null && title.length() > 0) { - builder.append(" - "); + if (separator) { + builder.append(" - "); + } builder.append(title); } try { -- cgit v1.2.3