AudioMetadata { public boolean check() throws Exception { format = FORMAT_UNSUPPORTED; File fileCopy = File.createTempFile("modeshape-sequencer-audio", ".tmp"); IoUtil.write(in, new BufferedOutputStream(new FileOutputStream(fileCopy))); if (mimeType.startsWith("audio/mpeg")) { format = FORMAT_MP3; audioFile = new MP3FileReader().read(fileCopy); } else if (mimeType.startsWith("audio/vorbis") || mimeType.startsWith("audio/x-vorbis") || mimeType.startsWith("audio/ogg")) { format = FORMAT_VORBIS; audioFile = new OggFileReader().read(fileCopy); } else if (mimeType.startsWith("audio/flac") || mimeType.startsWith("audio/x-flac")) { format = FORMAT_FLAC; audioFile = new FlacFileReader().read(fileCopy); } else if (mimeType.equals("audio/mp4") || mimeType.equals("video/mp4") || mimeType.equals("video/quicktime")) { format = FORMAT_MP4; audioFile = new Mp4FileReader().read(fileCopy); } else if (mimeType.equals("audio/x-ms-wma")) { format = FORMAT_WMA; audioFile = new AsfFileReader().read(fileCopy); } else if (mimeType.startsWith("audio/x-wav") || mimeType.startsWith("audio/wav")) { format = FORMAT_WAV; audioFile = new WavFileReader().read(fileCopy); } boolean deleted = false; try { deleted = fileCopy.delete(); } catch (SecurityException e) { } if (!deleted) { fileCopy.deleteOnExit(); } return checkSupportedAudio(); } AudioMetadata( InputStream inputStream,
                          final String mimeType ); boolean check(); int getFormat(); String getFormatName(); Long getBitrate(); Integer getSampleRate(); String getChannels(); Double getDuration(); String getTitle(); String getArtist(); String getAlbum(); String getYear(); String getComment(); String getTrack(); String getGenre(); List<AudioMetadataArtwork> getArtwork(); static final int FORMAT_MP3; static final int FORMAT_MP4; static final int FORMAT_VORBIS; static final int FORMAT_FLAC; static final int FORMAT_WMA; static final int FORMAT_WAV; static final int FORMAT_UNSUPPORTED; }
@Test public void shouldBeAbleToLoadMp3() throws Exception { AudioMetadata metadata = new AudioMetadata(getTestAudio("sample.mp3"), "audio/mpeg"); assertTrue(metadata.check()); assertMetaDataProperties(metadata, "mp3", "audio/mpeg", 64L, 44100, "2", 2.664, "Album", "Artist", "Comment", "Title", "2015", "1", "Speech", "image/jpeg", 3); }
@Test public void shouldBeAbleToLoadMp4() throws Exception { AudioMetadata metadata = new AudioMetadata(getTestAudio("sample.mp4"), "video/quicktime"); assertTrue(metadata.check()); assertMetaDataProperties(metadata, "mp4", "video/quicktime", 129L, 44100, "2", 2.0, "Album", "Artist", "Comment", "Title", "2015", "1", "Speech", "image/jpeg", null); }
@Test public void shouldBeAbleToLoadOggVorbis() throws Exception { AudioMetadata metadata = new AudioMetadata(getTestAudio("sample.ogg"), "audio/vorbis"); assertTrue(metadata.check()); assertMetaDataProperties(metadata, "ogg", "audio/vorbis", 112L, 44100, "2", 2.0, "Album", "Artist", "Comment", "Title", "2015", "1", "Speech", "image/jpeg", 3); }
@Test public void shouldBeAbleToLoadFlac() throws Exception { AudioMetadata metadata = new AudioMetadata(getTestAudio("sample.flac"), "audio/x-flac"); assertTrue(metadata.check()); assertMetaDataProperties(metadata, "flac", "audio/x-flac", 426L, 44100, "2", 2.0, "Album", "Artist", "Comment", "Title", "2015", "1", "Speech", "image/jpeg", 3); }