Error while playing sound in Java

萝らか妹 提交于 2019-12-13 04:04:12

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!