Java examples for Media:Audio
Determining the Encoding of a Sampled Audio File
import java.io.File; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import javax.sound.sampled.AudioFormat; import javax.sound.sampled.AudioInputStream; import javax.sound.sampled.AudioSystem; import javax.sound.sampled.UnsupportedAudioFileException; public class Main { public static void main(String[] args) throws Exception { try {/*from ww w . j a v a 2 s . c o m*/ // From file AudioInputStream stream = AudioSystem.getAudioInputStream(new File( "audiofile")); // From URL stream = AudioSystem.getAudioInputStream(new URL( "http://hostname/audiofile")); AudioFormat format = stream.getFormat(); if (format.getEncoding() == AudioFormat.Encoding.ULAW) { } else if (format.getEncoding() == AudioFormat.Encoding.ULAW) { } } catch (MalformedURLException e) { } catch (IOException e) { } catch (UnsupportedAudioFileException e) { // Audio format is not supported. } } }