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

后端 未结 2 1409
栀梦
栀梦 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:10

    You can actually play sound above 40 mb, if needed, thats how far i went :p, the problem is mostly eclipse, and to be more exact its the .metadata folder in your workspace i think its like a small plugin that only gets uploaded half of the time, so the problem lies with your editor and not the code, the code above is working perfectly since i could play songs without any trouble. Make sure your paths are correct, and try to get a correct version of the .metadata and you should be fine. A friend of mine had the same problem, and i gave him my copy of the workspace and .metadata and it worked perfectly.

    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题