package info.benjaminhill.wash;
import info.benjaminhill.utils.AbstractFileScan;
import java.io.File;
import java.io.IOException;
import javax.media.Manager;
import javax.media.MediaException;
import javax.media.MediaLocator;
import javax.media.Player;
public class FindDupMusic extends AbstractFileScan {
public static double getLength(final File fileLocation)
throws MediaException, IOException {
final MediaLocator mediaLocator = new MediaLocator(fileLocation
.getAbsolutePath());
final Player playMP3 = Manager.createPlayer(mediaLocator);
return playMP3.getDuration().getSeconds();
}
/**
* @param args
* @throws IOException
*/
public static void main(final String[] args) throws IOException {
final FindDupMusic fdm = new FindDupMusic();
fdm.run();
}
@Override
public void handleDirectory(final File dir) {
// Skip
}
@Override
public void handleFile(final File f) {
if (!f.getName().endsWith("mp3")) {
return;
}
try {
final double length = getLength(f);
System.out.println(length + " " + f.getAbsolutePath());
} catch (final MediaException e) {
e.printStackTrace();
} catch (final IOException e) {
e.printStackTrace();
}
}
}