Examples of AudioFileFormat


Examples of javax.sound.sampled.AudioFileFormat

                "mp3.original",/*"mp3.length.bytes",*/"mp3.frequency.hz",
                /*"mp3.length.frames",*/"mp3.mode","mp3.channels","mp3.version.mpeg",
                "mp3.framesize.bytes","mp3.vbr.scale","mp3.version.encoding",
                "mp3.header.pos","mp3.version.layer","mp3.crc"};
    String[] testPropsAF = {"vbr", "bitrate"};
    AudioFileFormat baseFileFormat = null;
    AudioFormat baseFormat = null;
    try
    {
      URL url = new URL(fileurl);
      baseFileFormat = AudioSystem.getAudioFileFormat(url);
      baseFormat = baseFileFormat.getFormat();
      if (out != null) out.println("-> URL : "+filename+" <-");
      if (out != null) out.println(baseFileFormat);
      if (baseFileFormat instanceof TAudioFileFormat)
      {
        Map properties = ((TAudioFileFormat)baseFileFormat).properties();
View Full Code Here

Examples of javax.sound.sampled.AudioFileFormat

    }
  }

  public void testPropertiesShoutcast()
  {
    AudioFileFormat baseFileFormat = null;
    AudioFormat baseFormat = null;
    String shoutURL = (String) props.getProperty("shoutcast");
    try
    {
      URL url = new URL(shoutURL);
      baseFileFormat = AudioSystem.getAudioFileFormat(url);
      baseFormat = baseFileFormat.getFormat();
      if (out != null) out.println("-> URL : "+url.toString()+" <-");
      if (out != null) out.println(baseFileFormat);
      if (baseFileFormat instanceof TAudioFileFormat)
      {
        Map properties = ((TAudioFileFormat)baseFileFormat).properties();
View Full Code Here

Examples of javax.sound.sampled.AudioFileFormat

  }

    public void _testDumpPropertiesFile()
    {
        File file = new File(filename);
        AudioFileFormat baseFileFormat = null;
        AudioFormat baseFormat = null;
        try
        {
            baseFileFormat = AudioSystem.getAudioFileFormat(file);
            baseFormat = baseFileFormat.getFormat();
            if (out != null) out.println("-> Filename : "+filename+" <-");
            if (baseFileFormat instanceof TAudioFileFormat)
            {
                Map properties = ((TAudioFileFormat)baseFileFormat).properties();
                Iterator it = properties.keySet().iterator();
View Full Code Here

Examples of javax.sound.sampled.AudioFileFormat

     * an unsupported format.
     */
    public static String getAudioFileFormatData(File file)
            throws Exception {
        try {
            AudioFileFormat audio_file_format = AudioSystem.getAudioFileFormat(file);

            String file_name = file.getName() + "\n";
            String file_type = audio_file_format.getType().toString() + "\n";
            String file_size = (audio_file_format.getByteLength() / 1024) + " kilobytes\n";
            String length_of_audio_data = audio_file_format.getFrameLength() + " sample frames\n";
            String time_duration = audio_file_format.getFrameLength() / audio_file_format.getFormat().getFrameRate() + " seconds\n";
            String additional_properties = audio_file_format.properties() + "\n";

            StringBuilder data = new StringBuilder();
            data.append("FILE NAME: ").append(file_name);
            data.append("FILE TYPE: ").append(file_type);
            data.append("FILE SIZE: ").append(file_size);
            data.append("FRAMES OF AUDIO DATA: ").append(length_of_audio_data);
            data.append("TIME DURATION: ").append(time_duration);
            data.append("PROPERTIES: ").append(additional_properties);

            data.append("\n").append(getAudioFormatData(audio_file_format.getFormat()));

            return data.toString();
        } catch (UnsupportedAudioFileException ex) {
            throw new Exception("File " + file.getName() + " has an unsupported audio format.");
        } catch (IOException ex) {
View Full Code Here

Examples of javax.sound.sampled.AudioFileFormat

        // 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

            for (Entry<String, Object> entry : fileFormat.properties().entrySet()) {
                metadata.set(entry.getKey(), entry.getValue().toString());
            }
            for (Entry<String, Object> entry : audioFormat.properties().entrySet()) {
                metadata.set(entry.getKey(), entry.getValue().toString());
            }
View Full Code Here

Examples of javax.sound.sampled.AudioFileFormat

  }
  public long getLength(Float frameRate) throws IOException,UnsupportedAudioFileException{
    if(getStream().getFrameLength()>0){return getStream().getFrameLength();}
   
    Long      duration;
    AudioFileFormat audioFileFormat;
   
    if(file!=null){
      audioFileFormat = AudioSystem.getAudioFileFormat(file);
    }else if(url!=null){
      audioFileFormat = AudioSystem.getAudioFileFormat(url);
View Full Code Here

Examples of javax.sound.sampled.AudioFileFormat

    public void testAudioFileFormat() {
        AudioFormat af = new AudioFormat(AudioFormat.Encoding.ALAW, 1f, 2, 3,
                4, 5f, true);

        AudioFileFormat aff = new MyAudioFileFormat(AudioFileFormat.Type.AIFC,
                AudioSystem.NOT_SPECIFIED, af, 100);
        assertEquals(AudioFileFormat.Type.AIFC, aff.getType());
        assertEquals(AudioSystem.NOT_SPECIFIED, aff.getByteLength());
        assertEquals(af, aff.getFormat());
        assertEquals(100, aff.getFrameLength());
        assertNull(aff.properties());
        assertNull(aff.getProperty("key"));

        aff = new AudioFileFormat(AudioFileFormat.Type.WAVE, af, 10);
        assertEquals(AudioFileFormat.Type.WAVE, aff.getType());
        assertEquals(AudioSystem.NOT_SPECIFIED, aff.getByteLength());
        assertEquals(af, aff.getFormat());
        assertEquals(10, aff.getFrameLength());
        assertNull(aff.properties());
        assertNull(aff.getProperty("key"));

        HashMap<String, Object> prop = new HashMap<String, Object>();
        prop.put("duration", Long.valueOf(100));
        prop.put("title", "Title String");
        aff = new AudioFileFormat(AudioFileFormat.Type.AU, af,
                AudioSystem.NOT_SPECIFIED, prop);
        assertEquals(AudioFileFormat.Type.AU, aff.getType());
        assertEquals(AudioSystem.NOT_SPECIFIED, aff.getByteLength());
        assertEquals(af, aff.getFormat());
        assertEquals(AudioSystem.NOT_SPECIFIED, aff.getFrameLength());
        assertEquals(2, aff.properties().size());
        assertEquals(Long.valueOf(100), aff.properties().get("duration"));
        assertNull(aff.getProperty("key"));
        assertEquals("Title String", aff.getProperty("title"));
        try {
            aff.properties().put("aa", 1);
            fail("No expected UnsupportedOperationException");
        } catch (UnsupportedOperationException expected) {
        }

    }
View Full Code Here

Examples of javax.sound.sampled.AudioFileFormat

    @Override
    public JizzTrackInfo read(InputStream in) throws IOException,
            UnsupportedTrackTypeException {
        try {
            AudioFileFormat af = AudioSystem.getAudioFileFormat(in);

            String artist = objToStr(af.getProperty(PROPERTY_ARTIST));
            String title = objToStr(af.getProperty(PROPERTY_TITLE));

            return new JizzJavaSoundTrackInfoImpl(artist, title);
        } catch (UnsupportedAudioFileException uafEx) {
            throw new UnsupportedTrackTypeException(uafEx);
        }
View Full Code Here

Examples of javax.sound.sampled.AudioFileFormat

     */
    public AudioInputStream getAudioInputStream(InputStream stream) throws UnsupportedAudioFileException, IOException {
        // Save byte header since this method must return the stream opened at byte 0.
        final BufferedInputStream in = new BufferedInputStream(stream);
        in.mark(MAX_HEADER_SIZE);
        final AudioFileFormat format = getAudioFileFormat(in);
        in.reset();
        return new AudioInputStream(in, format.getFormat(), format.getFrameLength());
    }
View Full Code Here

Examples of javax.sound.sampled.AudioFileFormat

            throws IOException, TikaException {
        String type = metadata.get(Metadata.CONTENT_TYPE);
        if (type != null) {
            try {

                AudioFileFormat fileFormat = AudioSystem
                        .getAudioFileFormat(stream);

                AudioFormat format = fileFormat.getFormat();

                metadata.set("samplerate", Integer.toString((int) format
                        .getSampleRate()));
                metadata
                        .set("channels", Integer.toString(format.getChannels()));
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.