List of usage examples for javax.sound.sampled UnsupportedAudioFileException UnsupportedAudioFileException
public UnsupportedAudioFileException()
From source file:com.morty.podcast.writer.PodCastUtils.java
/** * Gets the duration of an audio file.//www .j ava 2 s. co m * @param file * @return the number of milliseconds in the file * @throws UnsupportedAudioFileException * @throws IOException */ public static long getDurationWithMp3Spi(File file) throws UnsupportedAudioFileException, IOException { m_logger.info("Determining length of MP3 file"); AudioFileFormat audioFile = AudioSystem.getAudioFileFormat(file); if (audioFile instanceof TAudioFileFormat) { m_logger.debug("TAudioFileFormat file found"); Map<?, ?> properties = ((TAudioFileFormat) audioFile).properties(); String key = "duration"; Long numberOfMicroseconds = (Long) properties.get(key); m_logger.info("Duration of [" + numberOfMicroseconds + "] microseconds"); return (numberOfMicroseconds.longValue() / 1000); } else { m_logger.info("Unsupported Mp3 fileformat."); throw new UnsupportedAudioFileException(); } }
From source file:org.getmansky.Cache.java
private static double getDuration(File file) throws UnsupportedAudioFileException, IOException { AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(file); if (fileFormat instanceof TAudioFileFormat) { Map<?, ?> properties = ((TAudioFileFormat) fileFormat).properties(); String key = "duration"; Long microseconds = (Long) properties.get(key); return microseconds / 1000; } else {// w w w. ja v a2s . c o m throw new UnsupportedAudioFileException(); } }