Package javax.sound.sampled

Examples of javax.sound.sampled.AudioFileFormat


        File file = trackData.getFile();

        String title = Util.removeExt(file.getName());
        trackData.setTagFieldValues(FieldKey.TITLE, title);
        try {
            AudioFileFormat format = AudioSystem.getAudioFileFormat(file);
            trackData.setStartPosition(0);
            AudioFormat audioFormat = format.getFormat();
            trackData.setSampleRate((int) audioFormat.getSampleRate());
            trackData.setTotalSamples(format.getFrameLength());
            trackData.setChannels(audioFormat.getChannels());
            trackData.setCodec(Util.getFileExt(file).toUpperCase());
            if (format.getFrameLength() > 0)
              trackData.setBitrate((int) (format.getByteLength() / format.getFrameLength() * audioFormat.getSampleRate() / 100));
        } catch (Exception e) {
            System.out.println("Couldn't read file: " + trackData.getFile());
        }
        return track;
    }
View Full Code Here


  public AudioFileFormat getAudioFileFormat(File file) throws UnsupportedAudioFileException, IOException {
    InputStream in = null;
    try {
      in = new BufferedInputStream(new FileInputStream(file));
      in.mark(1000);
      final AudioFileFormat aff = getAudioFileFormat(in, (int) file.length());
      in.reset();
      return aff;
    }
    finally {
      if(in!=null) in.close();
View Full Code Here

        canHandle = false;
      }
    }
    if(canHandle) {
      final AudioFormat format = new AudioFormat(AAC_ENCODING, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, mediaLength, AudioSystem.NOT_SPECIFIED, AudioSystem.NOT_SPECIFIED, true);
      return new AudioFileFormat(AAC, format, AudioSystem.NOT_SPECIFIED);
    }
    else throw new UnsupportedAudioFileException();
  }
View Full Code Here

  @Override
  public AudioInputStream getAudioInputStream(InputStream in) throws UnsupportedAudioFileException, IOException {
    try {
      if(!in.markSupported()) in = new BufferedInputStream(in);
      in.mark(1000);
      final AudioFileFormat aff = getAudioFileFormat(in, AudioSystem.NOT_SPECIFIED);
      in.reset();
      return new MP4AudioInputStream(in, aff.getFormat(), aff.getFrameLength());
    }
    catch(UnsupportedAudioFileException e) {
      in.reset();
      throw e;
    }
View Full Code Here

        // AudioSystem expects the stream to support the mark feature
        if (!stream.markSupported()) {
            stream = new BufferedInputStream(stream);
        }
        try {
            AudioFileFormat fileFormat = AudioSystem.getAudioFileFormat(stream);
            Type type = fileFormat.getType();
            if (type == Type.AIFC || type == Type.AIFF) {
                metadata.set(Metadata.CONTENT_TYPE, "audio/x-aiff");
            } else if (type == Type.AU || type == Type.SND) {
                metadata.set(Metadata.CONTENT_TYPE, "audio/basic");
            } else if (type == Type.WAVE) {
                metadata.set(Metadata.CONTENT_TYPE, "audio/x-wav");
            }

            AudioFormat audioFormat = fileFormat.getFormat();
            int channels = audioFormat.getChannels();
            if (channels != AudioSystem.NOT_SPECIFIED) {
                metadata.set("channels", String.valueOf(channels));
                // TODO: Use XMPDM.TRACKS? (see also frame rate in AudioFormat)
            }
            float rate = audioFormat.getSampleRate();
            if (rate != AudioSystem.NOT_SPECIFIED) {
                metadata.set("samplerate", String.valueOf(rate));
                metadata.set(
                        XMPDM.AUDIO_SAMPLE_RATE,
                        Integer.toString((int) rate));
            }
            int bits = audioFormat.getSampleSizeInBits();
            if (bits != AudioSystem.NOT_SPECIFIED) {
                metadata.set("bits", String.valueOf(bits));
                if (bits == 8) {
                    metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "8Int");
                } else if (bits == 16) {
                    metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "16Int");
                } else if (bits == 32) {
                    metadata.set(XMPDM.AUDIO_SAMPLE_TYPE, "32Int");
                }
            }
            metadata.set("encoding", audioFormat.getEncoding().toString());

            // Javadoc suggests that some of the following properties might
            // be available, but I had no success in finding any:

            // "duration" Long playback duration of the file in microseconds
            // "author" String name of the author of this file
            // "title" String title of this file
            // "copyright" String copyright message
            // "date" Date date of the recording or release
            // "comment" String an arbitrary text

            addMetadata(metadata, fileFormat.properties());
            addMetadata(metadata, audioFormat.properties());
        } catch (UnsupportedAudioFileException e) {
            // There is no way to know whether this exception was
            // caused by the document being corrupted or by the format
            // just being unsupported. So we do nothing.
View Full Code Here

    public AudioFileFormat getAudioFileFormat(InputStream stream)
            throws UnsupportedAudioFileException, IOException {

        stream.mark(200);
        AudioFileFormat format;
        try {
            format = internal_getAudioFileFormat(stream);
        } finally {
            stream.reset();
        }
View Full Code Here

            throw new UnsupportedAudioFileException();

        AudioFormat audioformat = new AudioFormat(
                Encoding.PCM_FLOAT, samplerate, bits, channels,
                framesize, samplerate, false);
        AudioFileFormat fileformat = new AudioFileFormat(
                AudioFileFormat.Type.WAVE, audioformat,
                AudioSystem.NOT_SPECIFIED);
        return fileformat;
    }
View Full Code Here

    }

    public AudioInputStream getAudioInputStream(InputStream stream)
            throws UnsupportedAudioFileException, IOException {

        AudioFileFormat format = getAudioFileFormat(stream);
        RIFFReader riffiterator = new RIFFReader(stream);
        if (!riffiterator.getFormat().equals("RIFF"))
            throw new UnsupportedAudioFileException();
        if (!riffiterator.getType().equals("WAVE"))
            throw new UnsupportedAudioFileException();
        while (riffiterator.hasNextChunk()) {
            RIFFReader chunk = riffiterator.nextChunk();
            if (chunk.getFormat().equals("data")) {
                return new AudioInputStream(chunk, format.getFormat(),
                        chunk.getSize());
            }
        }
        throw new UnsupportedAudioFileException();
    }
View Full Code Here

    }

    public AudioFileFormat getAudioFileFormat(URL url)
            throws UnsupportedAudioFileException, IOException {
        InputStream stream = url.openStream();
        AudioFileFormat format;
        try {
            format = getAudioFileFormat(new BufferedInputStream(stream));
        } finally {
            stream.close();
        }
View Full Code Here

    }

    public AudioFileFormat getAudioFileFormat(File file)
            throws UnsupportedAudioFileException, IOException {
        InputStream stream = new FileInputStream(file);
        AudioFileFormat format;
        try {
            format = getAudioFileFormat(new BufferedInputStream(stream));
        } finally {
            stream.close();
        }
View Full Code Here

TOP

Related Classes of javax.sound.sampled.AudioFileFormat

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.