aspose file tools*
The moose likes Applets and the fly likes Playing sounds Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Applets
Bookmark "Playing sounds" Watch "Playing sounds" New topic
Author

Playing sounds

colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
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
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
Is the desktop part of the classpath? It seems that it must be, though, or it wouldn't work for images.


Ping & DNS - my free Android networking tools app
colin shuker
Ranch Hand

Joined: Apr 11, 2005
Posts: 744
Yeh, I think it is. I can always execute jar files from desktop, or from within folders on the desktop.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42263
    
  64
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

Joined: Apr 11, 2005
Posts: 744
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

Joined: Apr 11, 2005
Posts: 744
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Playing sounds