So the idea is to read metadata recursively in a chosen directory, load their metadata and display it into a table.
Here is the simplified example of what I am doing.
public class AudioMetadataExtractorTest {
public static void main(String[] args) {
String audioFiles = "C:\\Music";
File dir = new File(audioFiles);
Collection col = checkData(dir);
for(Object object : col){
File fil = (File) object;
System.out.println(fil.getAbsolutePath());
try {
printMetaData(fil);
} catch (Exception e) {
e.printStackTrace();
}
}
System.out.println(col.size());
}
In this case I am using the apachi.commons library to gather all files.
public static Collection checkData(File dir){
Collection files = FileUtils.listFiles(
dir,
new RegexFileFilter("^(.*mp3)"),
DirectoryFileFilter.DIRECTORY
);
return files;
}
And with jaudiotagger read and print the metadata.
public static void printMetaData(File file) throws Exception {
AudioFile audioFile = null;
audioFile = AudioFileIO.read(file);
Tag tag = audioFile.getTag();
for (FieldKey key : FieldKey.values()) {
if(key==FieldKey.ALBUM){
System.out.println(key + " " + tag.getFirst(key));
}
}
}
While this code works, it is extremely slow. I am confident there is a more efficient way of doing this.
- Is it bad practice to loop over objects and cast them within the loop?
- Is the jaudiotagger library an intrinsically slow library?