[Android] AudioUtil: rewrite the cover files matching algo
Jean-Baptiste Kempf
git at videolan.org
Sat May 23 20:19:59 CEST 2015
vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Sat May 23 20:18:12 2015 +0200| [3868638673b04874c46c7cb5ab4d4f5dfe9708e4] | committer: Jean-Baptiste Kempf
AudioUtil: rewrite the cover files matching algo
The current one took any jpg or png file in the same folder...
The new one takes only the files that have the same filename and a list
of known files to be covers.
> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=3868638673b04874c46c7cb5ab4d4f5dfe9708e4
---
.../src/org/videolan/vlc/gui/audio/AudioUtil.java | 45 +++++++++++++++++---
1 file changed, 40 insertions(+), 5 deletions(-)
diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
index ed30b19..0c6db13 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioUtil.java
@@ -46,6 +46,7 @@ import org.videolan.vlc.util.Util;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
+import java.io.FilenameFilter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
@@ -220,12 +221,46 @@ public class AudioUtil {
private static String getCoverFromFolder(MediaWrapper media) {
File f = LibVlcUtil.URItoFile(media.getLocation());
- if (f != null && f.getParentFile() != null && f.getParentFile().listFiles() != null)
- for (File s : f.getParentFile().listFiles()) {
- if (s.getAbsolutePath().endsWith("png")
- || s.getAbsolutePath().endsWith("jpg"))
- return s.getAbsolutePath();
+ if (f == null)
+ return null;
+
+ File folder = f.getParentFile();
+ if (folder == null)
+ return null;
+
+ final String[] imageExt = { ".png", ".jpeg", ".jpg"};
+ final String[] coverImages = {
+ "Folder.jpg", /* Windows */
+ "AlbumArtSmall.jpg", /* Windows */
+ "AlbumArt.jpg", /* Windows */
+ "Album.jpg",
+ ".folder.png", /* KDE? */
+ "cover.jpg", /* rockbox */
+ "thumb.jpg"
+ };
+
+ /* Find the path without the extension */
+ int index = f.getName().lastIndexOf('.');
+ if (index > 0) {
+ final String name = f.getName().substring(0, index);
+ File[] files = folder.listFiles(new FilenameFilter() {
+ public boolean accept(File dir, String filename) {
+ return filename.startsWith(filename);
+ }
+ });
+ if (files.length > 0)
+ return files[0].getAbsolutePath();
+ }
+
+ /* Find the classic cover Images */
+ if ( folder.listFiles() != null) {
+ for (File file : folder.listFiles()) {
+ for (String str : coverImages) {
+ if (file.getAbsolutePath().endsWith(str))
+ return file.getAbsolutePath();
+ }
}
+ }
return null;
}
More information about the Android
mailing list