7 Replies - 5820 Views - Last Post: 09 May 2012 - 03:53 PM Rate Topic: -----

#1 Arezhik  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 3
  • Joined: 09-May 12

Jar file play sound problem

Posted 09 May 2012 - 02:22 PM

Been working on this project of mine, trying to get it into a jar file. But I run into the same problem some other do is That I cannot get the audio to work properly.

My code for calling the audio is this :

 	
				File temp = new File(SaverPaint.class.getClass().getClassLoader().getResource("src/NMP.wav").toString());
				Current_Sound = playSound(temp);
				
           //Debugging....
                                System.out.println("sound here");



The app still runs, just with no sound. I have also tried the getResourceAsStream() method with no avail.

I also put the sounds files inside the src folder.

Is This A Good Question/Topic? 1
  • +

Replies To: Jar file play sound problem

#2 DimitriV  Icon User is offline

  • They don't think it be like it is, but it do
  • member icon

Reputation: 583
  • View blog
  • Posts: 2,738
  • Joined: 24-July 11

Re: Jar file play sound problem

Posted 09 May 2012 - 02:27 PM

playSound, that's one of your methods? Maybe it has something to do with that.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Jar file play sound problem

Posted 09 May 2012 - 02:28 PM

It is an Application or an Applet ?
Does it run when you run it not from a .JAR ?
How did you jar your .jar ?
Was This Post Helpful? 0
  • +
  • -

#4 Arezhik  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 3
  • Joined: 09-May 12

Re: Jar file play sound problem

Posted 09 May 2012 - 02:35 PM

View PostDimitriV, on 09 May 2012 - 02:27 PM, said:

playSound, that's one of your methods? Maybe it has something to do with that.



Yes that is one of my methods. basically loads the multiple sound files I want listen to.

View Postpbl, on 09 May 2012 - 02:28 PM, said:

It is an Application or an Applet ?
Does it run when you run it not from a .JAR ?
How did you jar your .jar ?



Answers: It is an Application.

It runs when ran from eclipse, but when packaged into a runnable jar file the audio does not work but the rest of the app does.
Was This Post Helpful? 0
  • +
  • -

#5 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Jar file play sound problem

Posted 09 May 2012 - 02:49 PM

do:

> jar tf jarfile

to see if it is actually in the .jar and have a look there
http://www.dreaminco...9&#entry1619169
Was This Post Helpful? 0
  • +
  • -

#6 Arezhik  Icon User is offline

  • New D.I.C Head

Reputation: 2
  • View blog
  • Posts: 3
  • Joined: 09-May 12

Re: Jar file play sound problem

Posted 09 May 2012 - 03:25 PM

Hey guys thanks for the help, I actually just figured this out.

Since I am relatively new took me awhile but was able to change this code:

                                File temp = new File("src/sounds/ME2.wav");
				Current_Sound = playSound(temp);	
				System.out.println("sound here");



to:

                   InputStream path = getClass().getResourceAsStream("/sounds/ME2.wav");
				try{
					Current_Sound = AudioSystem.getClip();
					Current_Sound.open(AudioSystem.getAudioInputStream(path));
					Current_Sound.start();

				}catch(Exception fail){}



Turns out that the problem was that Java cannot convert a File Object to a Streaming Object directly. So I created the InputStream Object and used that instead.
Was This Post Helpful? 1
  • +
  • -

#7 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8324
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Jar file play sound problem

Posted 09 May 2012 - 03:33 PM

:^:
Was This Post Helpful? 0
  • +
  • -

#8 g00se  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2650
  • View blog
  • Posts: 11,179
  • Joined: 20-September 08

Re: Jar file play sound problem

Posted 09 May 2012 - 03:53 PM

Quote

}catch(Exception fail){}


(almost) never do that. You're saying "if there's an error, hide it from me, as i'm not interested in it or its cause"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1