Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 10 of 10

Thread: No sound in executable jar

  1. #1
    Junior Member
    Join Date
    May 2012
    Location
    Portland, OR
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default No sound in executable jar

    Ok now this is a real problem I believe. When I run this in eclipse it works fine, but once I export it to a jar the sound refuses to work. I have the 3 .wav files in a resources folder and I have a button that toggles the String 'file' between them.

    Relevant code:
            private class AudioClip extends Thread implements ActionListener{		
    		//private InputStream in;
    		private AudioStream as;
     
    		public void run(){
     
    			//Open audio stream
    			try{
    				//in = this.getClass().getResourceAsStream("/resources/" + file);
    				//as = new AudioStream(in);
    				as = new AudioStream(this.getClass().getResourceAsStream("/resources/" + file));
    				AudioPlayer.player.start(as);
     
    				Timer time = new Timer(5000, this);
    				time.setRepeats(false);
    				time.start();
     
    			}catch(FileNotFoundException e){
    				e.printStackTrace();
    			}catch (IOException e){
    				e.printStackTrace();
    			}
    		}
     
    		public void actionPerformed(ActionEvent event) {
    			AudioPlayer.player.stop(as);
    		}
    	}
    Last edited by BestSanchez; August 25th, 2012 at 02:41 AM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,358
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: No sound in executable jar

    Are the sound files in the jar file and are they in the correct folder?
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2012
    Location
    Portland, OR
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: No sound in executable jar

    I think so? And yeah I only have 'resources'.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    22,358
    Thanks
    56
    Thanked 2,376 Times in 2,346 Posts

    Default Re: No sound in executable jar

    I think so?
    Use a zip utility to look inside the jar file and make sure the files are where you expect them to be.

    BTW AudioClip is a poor name for your class. Java Se has a class with the same name.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2012
    Location
    Portland, OR
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: No sound in executable jar

    Yeah I figured, I was just running out of sound-related names haha. And yeah Izarc shows everything's there.

  6. #6
    Junior Member
    Join Date
    May 2012
    Location
    Portland, OR
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: No sound in executable jar

    Turns out the difference between 'r' and 'R' kept me from completing this project! Now i'm just glad i'm finally done.

  7. #7
    Member
    Join Date
    Apr 2012
    Posts
    163
    Thanks
    0
    Thanked 27 Times in 27 Posts

    Default Re: No sound in executable jar

    Quote Originally Posted by BestSanchez View Post
    Turns out the difference between 'r' and 'R' kept me from completing this project! Now i'm just glad i'm finally done.
    Always keep in mind that the language is case-sensitive

  8. #8
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    1,069
    Thanks
    7
    Thanked 215 Times in 191 Posts

    Default Re: No sound in executable jar

    Quote Originally Posted by BestSanchez View Post
    Turns out the difference between 'r' and 'R' kept me from completing this project! Now i'm just glad i'm finally done.
    Windows can be a bit misleading in this regard.

    getResource() returns you a URL and if this is a file: URL and you are on Windows case doesn't matter. Your program does the right right thing until... you create a jar archive. Then you are dealing with a jar: URL and case does matter for the names of entries in a such an archive.

    It pays to have a convention (all lower case with underscores, or camelCase like Java) for resource files.

  9. #9
    Junior Member
    Join Date
    May 2012
    Location
    Portland, OR
    Posts
    11
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: No sound in executable jar

    It was actually the name of the folder 'Resources'

  10. #10
    Super Moderator pbrockway2's Avatar
    Join Date
    Jan 2012
    Posts
    1,069
    Thanks
    7
    Thanked 215 Times in 191 Posts

    Default Re: No sound in executable jar

    Ah! Same thing applies, of course: directories also "map" to archive elements with case being honoured in the archive, but not in the (Windows) file system.

    In this case I think the "normal" thing to do would be to change the folder (directory) name, not the code. This would be in keeping with Java package naming conventions, and also how IDEs do things ("bin" and "src", not "Bin" and "Src").

  11. The Following User Says Thank You to pbrockway2 For This Useful Post:

    BestSanchez (August 25th, 2012)

Similar Threads

  1. Replies: 0
    Last Post: January 12th, 2012, 03:54 PM
  2. .jar executable
    By mwr76 in forum Java Theory & Questions
    Replies: 2
    Last Post: October 9th, 2011, 12:27 PM
  3. [SOLVED] no sound from executable jar file
    By cl2606 in forum What's Wrong With My Code?
    Replies: 17
    Last Post: June 8th, 2011, 07:41 PM
  4. Jar Executable File
    By The_Mexican in forum What's Wrong With My Code?
    Replies: 43
    Last Post: June 23rd, 2010, 04:53 PM
  5. Making executable JAR more "executable"
    By ni4ni in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 1st, 2010, 02:19 PM