tags:

views:

204

answers:

4

Is it possible to play a sound (.wav or .mp3) in a client's browser using a JSF web app?

I have tried using javax.sound.sampled.SourceDataLine and it worked on Windows, but when I deploy the .war on a Linux host I get this exception: "javax.sound.sampled.LineUnavailableException: Audio Device Unavailable"

A: 

I am not sure, javax.sound.sampled.LineUnavailableException indicating.

1.Application may be used by some other process

2.You may not have permission to access the audio device

3.Try with small file.

Thillakan
+2  A: 

Is it possible to play a sound (.wav or .mp3) in a client's browser using a JSF web app?

I should have mentioned that, but this has nothing to do with JSF or any other server-side technology. If you want to play a sound on the client-side, generate the appropriate client-side code, i.e. HTML here.

HTML 5 has an <audio> tag but, until it gets mainstream, see Playing Sounds on a Web Site and How To Play Sound (which does a good job at summarizing the solutions) to learn more on the <embed> tag and the <object> tag.

Pascal Thivent
+2  A: 

Java code executes on the server to generate web pages that are displayed in the client's browser. If you have JSF web app code using the javax.sound.sampled.SourceDataLine class, the sound will play on the server (if this is even possible...), not in the client's browser.

To play a sound at the client, you'll either have to reference an audio file in the web page as Pascal Thivent has posted, or you'll have to play the sound through a Flash/Silverlight/Java Applet plugin referenced in the page.

Nate
+1  A: 

I have tried using javax.sound.sampled.SourceDataLine and it worked on Windows, but when I deploy the .war on a Linux host I get this exception: "javax.sound.sampled.LineUnavailableException: Audio Device Unavailable"

This exception literally means that the machine where the code runs doesn't have an audio device. I can imagine that it is very reasonable that webservers doesn't have any audio device, this namely doesn't make any sense.

As others have pointed out, you need to play sound at the client machine. You can find here a lot of background information and examples.

BalusC