getAudioInputStream导致异常

时间:2018-06-04 15:07:16

标签: java javasound illegalargumentexception

我试图制作一个非常简单的程序来播放声音文件。

到目前为止我只有:

import java.io.File;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;

public class SoundTest {

    public static void main(String[] args) {

        File sound = new File("/home/pierce/Downloads/clapping.wav");
        playSound(sound);

    }

    static void playSound(File sound) {
        try {
            Clip clip = AudioSystem.getClip();
            clip.open(AudioSystem.getAudioInputStream(sound));
        } catch(Exception e) {
            System.out.println("Something failed");
        }
    }

}

添加了行" clip.open(AudioSystem.getAudioInputStream(sound));"后,我开始在异常中收到消息。基本上我不知道为什么。任何帮助将不胜感激。

如果有必要了解我的目标,我会尝试关注this教程。

由于

编辑:根据要求进行堆栈跟踪:

java.lang.IllegalArgumentException: Invalid format
    at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.createStream(PulseAudioDataLine.java:142)
    at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:99)
    at org.classpath.icedtea.pulseaudio.PulseAudioDataLine.open(PulseAudioDataLine.java:283)
    at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:402)
    at org.classpath.icedtea.pulseaudio.PulseAudioClip.open(PulseAudioClip.java:453)
    at SoundTest.playSound(SoundTest.java:17)
    at SoundTest.main(SoundTest.java:10)

0 个答案:

没有答案