0

i'm trying to export my game with bunch of music. when i exported game with music(file size is 300mb(resources folder is about 300 mb size))

when i run the jar then i hear no sound. i tried with cmd it shows following error:

enter image description here

Any Help?

Edit

SoundManager Class:

package com.memequickie.sound;

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

public class SoundManager {
    Clip clip;
    public boolean playSound(File sound) {
        boolean ended = false;
        try {
            clip = AudioSystem.getClip();
            clip.open(AudioSystem.getAudioInputStream(sound));
            clip.start();
            if(clip.getMicrosecondLength() == clip.getMicrosecondPosition()) 
            {
                ended = true;
            }
        } catch(Exception e) {
            System.out.println("Error with playing sound.");
            e.printStackTrace();
        }
        return ended;
    }

    public void stopSound() {
        clip.stop();
    }
}

Edit I tried inputstream and still can't get it to working. enter image description here

1 Answers1

0

AudioSystem.getAudioInputStream(File) expects Music6.wav as a real file, not as a zipped file inside the JAR.

If you want to ship your audio files inside the JAR, you have to use AudioSystem.getAudioInputStream(InputStream) with the audio file as InputStream wrapped in a BufferedInputStream instead.

howlger
  • 31,050
  • 11
  • 59
  • 99
  • Please see Edit section in my post. –  Sep 16 '17 at 21:23
  • If you need a file (because you want to mark and reset the audio, which seems not supported with `InputStream`s), you only have the two options to not pack the audio files into the JAR file or to unpack the audio file temporarily before using it. – howlger Sep 16 '17 at 21:36
  • I just want to play music files back. no fancy stuff. –  Sep 16 '17 at 21:38
  • Use `new BufferedInputStream(InputStream)` instead directly the `InputStream` from `getClass().getResourceAsStream()`. – howlger Sep 16 '17 at 21:49