error playing sound java (No line matching interface Clip supporting format)

后端 未结 2 1408
栀梦
栀梦 2021-01-03 02:39

We are trying to integrated sound in one of our project, my team members don\'t get this error, and I get it on two different machines.

Stack trace:

2条回答
  •  感情败类
    2021-01-03 03:19

    I was experiencing this same problem on a raspberry pi. It would play the first 5 files just fine, then I'd get the error. It turned out that I was not closing the clip when I needed to.

    Clip clip = AudioSystem.getClip();
    clip.addLineListener(event -> {
        if(LineEvent.Type.STOP.equals(event.getType())) {
            clip.close();
        }
    });
    ByteArrayInputStream audioBytes = new ByteArrayInputStream(SOUNDS.get(file));
    AudioInputStream inputStream = AudioSystem.getAudioInputStream(audioBytes);
    clip.open(inputStream);
    clip.start();
    

    After adding the line listener and closing the clip when it stopped, the errors went away.

提交回复
热议问题