-2

enter image description here

enter image description here

enter image description here

Hello, i got some trouble with using Sounds in java. I just wanted to implement some fancy 8 bit sounds to my newest retro 2d game.... when i run it in java eclipse everything is fine and the sounds work....

but as soon as i run the finished application (the application itself works perfect...) but the sounds wont play and there is the error you can see in the 3d picture.

picture 1 shows my "sound method" and picture 2 how i use it.

How could i fix this?

Janik
  • 37
  • 6
  • Possible duplicate; try these answers: [java.io.IOException: mark/reset not supported](http://stackoverflow.com/a/29777139/1248974), [java.io.IOException: mark/reset not supported](http://stackoverflow.com/a/5529906/1248974). Basically, "the input stream you provided does not support setting a mark and resetting the stream to that mark." Try wrapping your FileInputStream inside a BufferedInputStream" as shown in [this answer](http://stackoverflow.com/a/29777139/1248974), or use a different audio file that does support "mark/reset". – chickity china chinese chicken Sep 02 '16 at 02:13
  • In the future, please don't upload screenshots of your code, stacktraces or console output, but rather copy and paste the text into the question, highlight it and press the `{}` code format button for easier debugging and running of your code by other users. thanks. – chickity china chinese chicken Sep 02 '16 at 02:27
  • ohh alright...... that may explains the downvotes i got.... thank you for telling me that.... i didnt know that. and i managed to solve the problem. I posted the changed code in my answer. but thanks for your help anyways! – Janik Sep 02 '16 at 14:14
  • Cool, no worries, glad to hear you figured it out, and thanks for posting your answer! – chickity china chinese chicken Sep 02 '16 at 16:14

1 Answers1

0

I found the solution. I changed the code of my audio method slightly.... and for some reason it works now. here's the code of it.

 public void playSound(String soundFile) {
        try {

            AudioInputStream audioIn = AudioSystem.getAudioInputStream(this.getClass().getResource("/Sounds/" + soundFile));
            Clip clip = AudioSystem.getClip();
            clip.open(audioIn);
            clip.start();
        } catch (UnsupportedAudioFileException e) {
             e.printStackTrace();
          } catch (IOException e) {
             e.printStackTrace();
          } catch (LineUnavailableException e) {
             e.printStackTrace();
          }
    }
Janik
  • 37
  • 6