Play wave file using AudioFormat in java
Posted
by angelina
on Stack Overflow
See other posts from Stack Overflow
or by angelina
Published on 2010-06-02T07:10:44Z
Indexed on
2010/06/02
7:13 UTC
Read the original article
Hit count: 344
java
Dear all,
I m getting following exception while running my code on linux operating system.This code works fine on windows operating system.below is the exception and code used.
java.lang.IllegalArgumentException: No line matching interface Clip supporting format PCM_SIGNED unknown sample rate, 16 bit, stereo, 4 bytes/frame, big-endian is supported.
AudioFormat format = sourceaudio.getFormat();
format = new AudioFormat(
AudioFormat.Encoding.PCM_SIGNED,
format.getSampleRate(),
format.getSampleSizeInBits() * 2,
format.getChannels(),
format.getFrameSize() * 2,
format.getFrameRate(),
true);
AudioFileFormat.Type targettype = AudioFileFormat.Type.WAVE;
AudioInputStream targetaudiostream = AudioSystem.getAudioInputStream(format, sourceaudio);
sourceaudio.close();
targetaudiostream.close();
System.out.println("55555555");
URL url = new URL("http://localhost:8084/newvideo/PCMfile.wav");
Clip clip = AudioSystem.getClip();
AudioInputStream ais = AudioSystem.getAudioInputStream(url);
clip.open(ais);
System.out.println("seconds: " + (clip.getMicrosecondLength() / 1000000));
© Stack Overflow or respective owner