• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Playing sounds

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello fellow javarians

I'm using eclipse, from inside eclipse I have an application.
I am able to load an audio clip using:

Then passing in the string "res/sounds/music.wav" for example.

But when I JAR the application, then place the JAR file on desktop alongside "res/sounds/music.wav", then it doesn't work.

Its annoying, because it works fine with the images, but not sounds.
Can anyone help?

Thanks very much!
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the desktop part of the classpath? It seems that it must be, though, or it wouldn't work for images.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeh, I think it is. I can always execute jar files from desktop, or from within folders on the desktop.
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not the same thing. It's perfectly possible to double-click and run jar files in a directory without the directory being in the classpath.

But since the mechanism used to load that wav file relies on the file being in the classpath, it's not going to work if the directory it's in now (the Desktop directory) is not in the classpath.

Using this mechanism for resources that are not in the jar file itself is error-prone for exactly this reason.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yeh, but I've tried putting resources in the jar file, that doesn't work either, or if it does, it will only work on my machine, or it wont work on a mac, or something annoying.

I give up
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I saved the wav file "sounds/music.wav" in with jar file.
When I run the jar file from my desktop, sometimes the whole file will play, sometimes just a couple of seconds.

When I run the application from within eclipse it works perfectly.
Is there any way I can fix it so the sound works properly when I run the jar from my desktop?

Thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic