1

I want to play sound in the background of my game launcher but when i try to play sound i get this error. Failed to allocate clip data: Requested buffer too large.

Here is my sound code:

    public static void Sound() {
    try {
        AudioInputStream audio = AudioSystem.getAudioInputStream(new File("LauncherBG.wav"));
        Clip clip = AudioSystem.getClip();
        clip.open(audio);
        clip.start();
        CStop = clip;
    }

    catch (UnsupportedAudioFileException uae) {
        System.out.println(uae);
    } catch (IOException ioe) {
        System.out.println(ioe);
    } catch (LineUnavailableException lua) {
        System.out.println(lua);
    }
}

the wav is 16mb and it is 1:33 mins long please help

Andrew Thompson
  • 168,117
  • 40
  • 217
  • 433
DarkDays
  • 11
  • 2
  • A typical Java Sound Clip instance will hold 2 seconds of 16 bit stereo, CD quality sound. Use [`BigClip`](http://stackoverflow.com/a/9470886/418556) for large clips. I have heard it play CD quality sound of tracks lasting 22 minutes. – Andrew Thompson Jan 03 '13 at 08:01
  • @AndrewThompson code eg i tried but i couldn't get it to work – DarkDays Jan 03 '13 at 08:12
  • Why not, was it on strike? – Andrew Thompson Jan 03 '13 at 08:15
  • @AndrewThompson it just crashes my program – DarkDays Jan 03 '13 at 08:17
  • @AndrewThompson Exception in thread "main" java.lang.ClassCastException: com.sun.media.sound.MixerClip cannot be cast to BTec.BrettSmith.Poke3D.Sound.BigClip at BTec.BrettSmith.Poke3D.gui.Launcher.Sound(Launcher.java:76) at BTec.BrettSmith.Poke3D.gui.Launcher.startMenu(Launcher.java:102) at BTec.BrettSmith.Poke3D.gui.Launcher.(Launcher.java:69) at BTec.BrettSmith.Poke3D.Display.getLauncherInstance(Display.java:56) at BTec.BrettSmith.Poke3D.Display.main(Display.java:71) – DarkDays Jan 03 '13 at 08:25

0 Answers0