List of usage examples for javax.sound.sampled UnsupportedAudioFileException UnsupportedAudioFileException
public UnsupportedAudioFileException(final String message)
From source file:uk.co.modularaudio.service.audiofileioregistry.impl.AudioFileIORegistryServiceImpl.java
@Override public AudioFileIOService getAudioFileIOServiceForFormatAndDirection(final AudioFileFormat format, final AudioFileDirection direction) throws DatastoreException, RecordNotFoundException, UnsupportedAudioFileException { switch (direction) { case ENCODE: { final AudioFileIOService fis = formatToEncodingServiceMap.get(format); if (fis == null) { throw new UnsupportedAudioFileException("File format not handled for encoding"); }/* ww w .j a va2s . co m*/ return fis; } case DECODE: default: { final AudioFileIOService fis = formatToDecodingServiceMap.get(format); if (fis == null) { throw new UnsupportedAudioFileException("File format not handled for decoding"); } return fis; } } }
From source file:uk.co.modularaudio.service.audiofileioregistry.impl.AudioFileIORegistryServiceImpl.java
@Override public AudioFileFormat sniffFileFormatOfFile(final String path) throws DatastoreException, RecordNotFoundException, UnsupportedAudioFileException { AudioFileFormat retVal = AudioFileFormat.UNKNOWN; for (final AudioFileIOService oneService : services) { try {/* ww w . j a v a 2s. com*/ final AudioFileFormat foundFormat = oneService.sniffFileFormatOfFile(path); retVal = foundFormat; if (retVal != AudioFileFormat.UNKNOWN) { if (log.isTraceEnabled()) { log.trace("Service \"" + oneService.getClass().getSimpleName() + "\" recognised format as " + foundFormat.toString()); } return retVal; } } catch (final RecordNotFoundException rnfe) { if (log.isTraceEnabled()) { log.trace("Service \"" + oneService.getClass().getSimpleName() + "\" threw rnfe for file " + path); } } catch (final UnsupportedAudioFileException uafe) { if (log.isTraceEnabled()) { log.trace("Service \"" + oneService.getClass().getSimpleName() + "\" threw uafe for file " + path); } } } if (retVal == AudioFileFormat.UNKNOWN) { throw new UnsupportedAudioFileException("Could not determine type of file \"" + path + "\""); } return retVal; }
From source file:uk.co.modularaudio.service.libmpg123audiofileio.LibMpg123AudioFileIOService.java
private SWIGTYPE_p_mpg123_handle_struct openHandle(final String path) throws DatastoreException, UnsupportedAudioFileException { final CArrayInt errorInt = new CArrayInt(1); final SWIGTYPE_p_int error = errorInt.cast(); final SWIGTYPE_p_mpg123_handle_struct handle = libmpg123.mpg123_new(null, error); final int errorValue = errorInt.getitem(0); boolean isOpen = false; boolean isMp3 = false; try {//from w ww. ja v a 2 s. c o m if (errorValue != mpg123_errors.MPG123_OK.swigValue()) { throw new DatastoreException("Error thrown in mpg123_new: " + errorValue); } libmpg123.mpg123_param(handle, mpg123_parms.MPG123_ADD_FLAGS, mpg123_param_flags.MPG123_FORCE_FLOAT.swigValue(), 0.0f); final int openSuccess = libmpg123.mpg123_open(handle, path); if (openSuccess != mpg123_errors.MPG123_OK.swigValue()) { throw new DatastoreException("Failed in mpg123_open: " + openSuccess); } isOpen = true; final int formatCheck = libmpg123.CheckFormat(handle); if (formatCheck != mpg123_errors.MPG123_OK.swigValue()) { throw new UnsupportedAudioFileException("File is not an MP3: " + path); } final int scanSuccess = libmpg123.mpg123_scan(handle); if (scanSuccess != mpg123_errors.MPG123_OK.swigValue()) { throw new UnsupportedAudioFileException("File failed mpg123_scan - not an MP3: " + path); } final long endSeek = libmpg123.mpg123_seek(handle, 0, SEEK_END); if (endSeek == 0) { throw new UnsupportedAudioFileException("File failed end seek - not an MP3"); } final long tellFrames = libmpg123.mpg123_tell(handle); if (tellFrames == 0) { throw new UnsupportedAudioFileException("File has tell of zero after scan - not an MP3"); } final long numFrames = libmpg123.mpg123_length(handle); if (numFrames == 0) { throw new UnsupportedAudioFileException( "File has zero length after scan - guessing it's not an MP3"); } final long seekResult = libmpg123.mpg123_seek(handle, 0, SEEK_SET); if (seekResult != mpg123_errors.MPG123_OK.swigValue()) { throw new UnsupportedAudioFileException("Filed failed mpg123_seek - not an MP3: " + path); } isMp3 = true; } finally { // Cleanup depends on if it's an mp3 or not. // If it isn't cleanup everything. if (isOpen && !isMp3) { final int closeSuccess = libmpg123.mpg123_close(handle); if (closeSuccess != mpg123_errors.MPG123_OK.swigValue()) { if (log.isErrorEnabled()) { log.error("Failed during non-mp3 close: " + closeSuccess); } } libmpg123.mpg123_delete(handle); } errorInt.delete(); } return handle; }
From source file:uk.co.modularaudio.service.libsndfileaudiofileio.LibSndfileAudioFileIOService.java
@Override public AudioFileHandleAtom openForRead(final String absPath) throws DatastoreException, IOException, UnsupportedAudioFileException { if (log.isDebugEnabled()) { log.debug("Attempting to open \"" + absPath + "\""); }//from w w w .ja v a 2 s. co m final SF_INFO sfInfo = new SF_INFO(); SWIGTYPE_p_SNDFILE_tag sndfilePtr = null; try { sndfilePtr = libsndfile.sf_open(absPath, libsndfile.SFM_READ, sfInfo); final int format = sfInfo.getFormat(); final AudioFileFormat aff = decodeLibsndfileFormat(format); if (aff == AudioFileFormat.UNKNOWN) { throw new UnsupportedAudioFileException("File format unsupported."); } final SampleBits sb = SampleBits.SAMPLE_FLOAT; final DataRate dataRate = DataRate.fromFrequency(sfInfo.getSamplerate()); final int numChannels = sfInfo.getChannels(); final long numFrames = sfInfo.getFrames(); String libraryPath = absPath; if (!FileUtilities.isRelativePath(libraryPath)) { final String userMusicDir = audioFileIORegistryService.getUserMusicDir(); if (libraryPath.startsWith(userMusicDir)) { libraryPath = libraryPath.substring(userMusicDir.length() + 1); } } final StaticMetadata sm = new StaticMetadata(aff, dataRate, sb, numChannels, numFrames, libraryPath); final LibSndfileAtom retVal = new LibSndfileAtom(this, AudioFileDirection.DECODE, sm, sfInfo, sndfilePtr); // We're good, set it to null so we don't close it. sndfilePtr = null; return retVal; } catch (final UnknownDataRateException udre) { final String msg = "UnknownDataRateException from sfInfo: " + udre.toString(); throw new DatastoreException(msg, udre); } finally { if (sndfilePtr != null) { final int closeSuccess = libsndfile.sf_close(sndfilePtr); if (closeSuccess != 0) { log.error("Failed in libsndfile close during cleanup"); } } sfInfo.delete(); } }
From source file:xtrememp.tag.GenericInfo.java
/** * Load and parse info from a File.//from w w w. j av a 2 s .c om * * @param input * @throws IOException */ @Override public void load(File input) throws IOException, UnsupportedAudioFileException { size = input.length(); location = input.getPath(); title = FilenameUtils.getBaseName(input.getName()); try { AudioFile audioFile = AudioFileIO.read(input); AudioHeader audioHeader = audioFile.getAudioHeader(); if (audioHeader != null) { encodingType = audioHeader.getEncodingType(); format = audioHeader.getFormat(); sampleRate = audioHeader.getSampleRate(); sampleRateAsNumber = audioHeader.getSampleRateAsNumber(); bitRate = audioHeader.getBitRate(); bitRateAsNumber = audioHeader.getBitRateAsNumber(); duration = audioHeader.getTrackLength(); channels = audioHeader.getChannels(); } Tag tag = audioFile.getTag(); if (tag != null) { title = tag.getFirst(FieldKey.TITLE); artist = tag.getFirst(FieldKey.ARTIST); album = tag.getFirst(FieldKey.ALBUM); year = tag.getFirst(FieldKey.YEAR); genre = tag.getFirst(FieldKey.GENRE); track = tag.getFirst(FieldKey.TRACK); comment = tag.getFirst(FieldKey.COMMENT); artwork = tag.getFirstArtwork(); } } catch (CannotReadException ex) { throw new IOException(ex); } catch (TagException ex) { throw new UnsupportedAudioFileException(ex.getMessage()); } catch (ReadOnlyFileException ex) { throw new IOException(ex); } catch (InvalidAudioFrameException ex) { throw new UnsupportedAudioFileException(ex.getMessage()); } }