1 Reply Latest reply: Apr 20, 2011 1:21 PM by baftos RSS

    Executable Jar fails to play audio clip, but OK from the command line?

    848783
      I've created an executable jar file using Netbeans. The jar file executes with a double-click, but no audio can be heard when the buttons are pressed.

      The program executes OK in NetBeans, so I can't debug the problem there. The program executes OK using the command line, so I can't debug the problem by using System.out.println().

      The method to play the audio clip looks like this:

      ---------------------------
        public void play() {
              try {
                  // System.out.print("-- Audio_path: " + path );
      
                  in = Main.class.getResourceAsStream(path);
                  // System.out.print(" in: " + in.toString() );
      
                  AudioStream as = new AudioStream(in);
                  // System.out.println(" as: " + as.toString() + " len:" + as.getLength() );
      
                  AudioPlayer.player.start(as);
              } catch (Exception ex) {
                  System.err.println("Caught exception in AudioClip.play: "
                          + ex.getMessage());
              }
          }
      ---------------------------

      $ java -jar zEx001_Buttons_triggering_Audio.jar <<<---- Works.

      Also, all the files are present in the jar:

      -----------------------------
      $ jar -tf zEx001_Buttons_triggering_Audio.jar
      META-INF/
      META-INF/MANIFEST.MF
      zex001_buttons_triggering_audio/
      zex001_buttons_triggering_audio/resources/
      zex001_buttons_triggering_audio/AudioClip.class
      zex001_buttons_triggering_audio/Main$1.class
      zex001_buttons_triggering_audio/Main.class
      zex001_buttons_triggering_audio/resources/bling.wav
      zex001_buttons_triggering_audio/resources/boing.wav
      -----------------------------

      I'll find a way to post the source and NetBeans project if anyone is interested.

      Edited by: 845780 on Mar 19, 2011 5:25 PM