1

My RPi is Zero W and using Raspbian Jessie 4.9.35 / Oracle JDK8 1.8.0_65.

I'm having problem with loading audio clips on Java Program with RPi. I have two audio files named "piano_0.wav" and "piano_1.wav" and they are different audio files.

I used this to load the clip:

Clip loadClip(String path) {
    Clip clip = null;
    try {
        clip = AudioSystem.getClip();
        AudioInputStream stream = AudioSystem.getAudioInputStream(new File(path));
        clip.open(stream);
    } catch (Exception e) {
        Logger.getLogger(MusicManager.class.getName()).log(Level.SEVERE, null, e);
    }
    return clip;
}

When I try to load piano_0.wav, there's no error logs and can play returned Clip. but When I try to load piano_1.wav program throws exception:

javax.sound.sampled.LineUnavailableException: line with format PCM_SIGNED 44100.0 Hz, 16 bit, stereo, 4 bytes/frame, little-endian not supported.
at com.sun.media.sound.DirectAudioDevice$DirectDL.implOpen(DirectAudioDevice.java:513)
at com.sun.media.sound.DirectAudioDevice$DirectClip.implOpen(DirectAudioDevice.java:1304)
at com.sun.media.sound.AbstractDataLine.open(AbstractDataLine.java:121)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1085)
at com.sun.media.sound.DirectAudioDevice$DirectClip.open(DirectAudioDevice.java:1175)
at beatstairscmd.BeatStairsCMD.testMusicClip(BeatStairsCMD.java:81)
at beatstairscmd.BeatStairsCMD.main(BeatStairsCMD.java:42)

But when I used this code on my Desktop there's no problem to load more clips. I already tried solutions with init the clip with other ways instead of AudioSystem.getClip() and there's no changes.

How should I fix this problem?

0

I managed to fix this by passing a different Mixer to getClip(MixerInfo) rather than relying on the default action of getClip(). I first called AudioSystem.getMixerInfo() to get a list of the audio mixers available and print them out to the console. Then I just tried them one my one until I found one that worked (actually, it was the second one, so it didn't take too long).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.