update MetaDataExtractor

This commit is contained in:
Christian Schneppe 2020-02-03 21:46:26 +01:00
parent 29bc3e9c7b
commit 3c3c645c68
No known key found for this signature in database
GPG key ID: F30B8D686B44D87E

View file

@ -1183,17 +1183,30 @@ public class FileBackend {
} }
private String getAudioTitleArtist(File file) { private String getAudioTitleArtist(File file) {
String artist;
String title;
StringBuilder builder = new StringBuilder();
try { try {
MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever(); MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
mediaMetadataRetriever.setDataSource(file.toString()); mediaMetadataRetriever.setDataSource(file.toString());
StringBuilder builder = new StringBuilder(); artist = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
String artist = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST); if (artist == null) {
String title = mediaMetadataRetriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE); 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) { if (artist != null && artist.length() > 0) {
builder.append(artist); builder.append(artist);
separator = true;
} }
if (title != null && title.length() > 0) { if (title != null && title.length() > 0) {
if (separator) {
builder.append(" - "); builder.append(" - ");
}
builder.append(title); builder.append(title);
} }
try { try {