问题
I'm trying to play a sound in my Java Application, but every time I call the method I get this exception: javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 48000.0 Hz, 24 bit, mono, 3 bytes/frame, little-endian not supported.
Here's the code:
AudioInputStream audio = AudioSystem.getAudioInputStream(new File("src/media/ding2.wav"));
Clip clip = AudioSystem.getClip();
clip.open(audio);
clip.start();
I tried to play a file by passing a URL and it works fine, but with my "ding2.wav" nothing works.
Thanks in advance for your help.
回答1:
By looking over HERE in Documention, the LineUnavailableException arises when the line is not Available, or the requested resource is in use by Another Application,
Make Sure that your audio file is not open in any other application.
EDIT
As the error message says :line with format PCM_SIGNED 48000.0 Hz, 24 bit, mono, 3 bytes/frame the file format you are providing is not supported. and as you said I tried to play a file by passing a URL and it works fine, put the Old file back and check the file format by using
System.out.println(audio.getFormat());
and check what was the file format of that file , whether that was same to the above _line with format PCM_SIGNED 48000.0 Hz, 24 bit, mono, 3 _ or not,
来源:https://stackoverflow.com/questions/21887756/error-while-playing-sound-in-java