Determining the File Format of a Sampled Audio File - Java Media

Java examples for Media:Audio

Description

Determining the File Format of a Sampled Audio File

Demo Code

import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;

import javax.sound.sampled.AudioFileFormat;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.UnsupportedAudioFileException;

public class Main {
  public void m() throws Exception {
    try {/*from w  w  w.  j  a va2  s  .  c o  m*/
      // From file
      AudioFileFormat fformat = AudioSystem.getAudioFileFormat(new File(
          "audiofile"));

      // From URL
      fformat = AudioSystem.getAudioFileFormat(new URL(
          "http://hostname/audiofile"));

      if (fformat.getType() == AudioFileFormat.Type.AIFC) {
      } else if (fformat.getType() == AudioFileFormat.Type.AIFF) {
      } else if (fformat.getType() == AudioFileFormat.Type.AU) {
      } else if (fformat.getType() == AudioFileFormat.Type.WAVE) {
      }
    } catch (MalformedURLException e) {
    } catch (IOException e) {
    } catch (UnsupportedAudioFileException e) {
      // File format is not supported.
    }
  }
}

Related Tutorials