wood burning stoves
The moose likes JavaFX and the fly likes Playing sounds files Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JavaFX
Bookmark "Playing sounds files" Watch "Playing sounds files" New topic

Playing sounds files

Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

Hi Rancher

Please, someone guide me.

I am building a video game, and I trying to play a sound file when the user change a option.

I am using this code

And when the user change the option menu on the GUI, I use:

But, when I try to change another option, and use play() function again, No sound nothing.

Someone can help me with this.

Rory Evans

Joined: Feb 19, 2010
Posts: 18
I have absolutely no experience of Java FX - but from your description (the file only plays once and then never again) I'd say that when a file has finished playing, its play position doesn't get set back to the beginning of the track.

This would mean that calling play() again would cause nothing to happen since the play position is already at the end of the track.

I had a quick look at the API and noticed that under the stop() function it says 'Stops playing, resets to beginning of media, and resets the play count'.

The play() function says 'Starts or resumes playing'.

I would say that you need to call stop() before calling play() so you can ensure the track will always play from the beginning.
Milton Ochoa
Ranch Hand

Joined: Oct 23, 2007
Posts: 336

Hi Rory Evans, Thank you for you answer.

Its true about you say.

But when I try that: (stop() and then play() again), its the same problem, no sound out comming.

I read on another forum this same problem, its seems that the API (JavaFX) have a problem with files with a small length. The Temporal solution that I could find around this issues, was using the audio API that is used in Applets.

For now I will wait, for one better solution.
Rob Spoor

Joined: Oct 27, 2005
Posts: 20276

Milton Ochoa wrote:Thankz

Sorry to nitpick but please UseRealWords: "thanks".

How To Ask Questions How To Answer Questions
I agree. Here's the link: http://aspose.com/file-tools
subject: Playing sounds files
It's not a secret anymore!