Java Sound format not supported

久未见 提交于 2019-12-19 19:12:25

问题


When using the following code: http://pastebin.com/5iVnttiP

I receive this error:

javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 16000.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
    at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(Unknown Source)
    at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
    at com.sun.media.sound.AbstractDataLine.open(Unknown Source)
    at com.AIComputer.model.Recorder.<init>(Recorder.java:124)
    at com.AIComputer.AIComputer.main(AIComputer.java:7)

Now I did some research and found out that not all sound cards support every format, however when running this demo: http://java.sun.com/products/java-media/sound/samples/JavaSoundDemo/ I managed to produce a recording using the exact same parameters (linear, 16000, 16, signed, little endian, stereo).

I have no idea what I'm doing wrong here (also since I'm still a beginner at Java coding).

Any help will be greatly appreciated!


回答1:


Can you say from which line on YOUR code this exception is thrown?

The docs of LineUnavailableException says

This situation arises most commonly when a requested line is already in use by another application.

You're opening two lines in your code. When you try to open the second one, the existence of the first one blocks it.



来源:https://stackoverflow.com/questions/11915469/java-sound-format-not-supported

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