aspose file tools*
The moose likes Servlets and the fly likes Sound in Servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sound in Servlet" Watch "Sound in Servlet" New topic
Author

Sound in Servlet

Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
Hello everyone, I tried playing a Wav in my Servlet, but for some reason is doesn't work.
(The goal is to sound the alarm when someone pull's the plug of my internet connection, which unforunately, happens way to often!)
This is the code I got. When I use it as a 'normal' application, it works, but when using it as a servlet, no sound is played.
Any help greatly appreciated!

Erik Pragt
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
I would think that the Applet AudioClip play method depends on the browser environment to get to the sound card. Does that really play outside the browser environment?
Bill
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
Hello William,
thanks for your reply. Yes, it really does play outside of a browser. In fact, I haven't tested if it works in a browser. I can post the real application tomorrow, if you want?
Any suggestions still very much appriciated!
Erik
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12803
    
    5
That creation of a File to represent the wav looks suspect. It depends on the "current" directory - you have no control over the current directory in a servlet - try it with an absolute path.
Bill
David Hibbs
Ranch Hand

Joined: Dec 19, 2002
Posts: 374
Seems likely to me that there's a catch or three...
a) The sound will only play when someone hits your servlet. If your internet connection is down, they can't hit your servlet, and hence, your sound will not play when your connection is cut.
b) The sound will play on the local machine, not the machine with browser (unless they are the same). The workaround would be to forward to a JSP that plays the sound file.
c) Using the Applet classes to play a sound from a servlet just seems... well, odd...


"Write beautiful code; then profile that beautiful code and make little bits of it uglier but faster." --The JavaPerformanceTuning.com team, Newsletter 039.
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
Originally posted by William Brogden:
That creation of a File to represent the wav looks suspect. It depends on the "current" directory - you have no control over the current directory in a servlet - try it with an absolute path.
Bill


William, I had no idea I could fall into that 'trap'. I thought the servlet would give a 'FileNotFoundException' or something when loading the .wav, but it didn't. Specifying the complete URI did the trick. Thanks!!
Erik
Erik Pragt
Ranch Hand

Joined: Sep 08, 2001
Posts: 125
Originally posted by David Hibbs:
Seems likely to me that there's a catch or three...
a) The sound will only play when someone hits your servlet. If your internet connection is down, they can't hit your servlet, and hence, your sound will not play when your connection is cut.
b) The sound will play on the local machine, not the machine with browser (unless they are the same). The workaround would be to forward to a JSP that plays the sound file.
c) Using the Applet classes to play a sound from a servlet just seems... well, odd...

Hello David, thanks for your reply. I'd like to comment on your post.
a) true, but when hitting the servlet, a flag is turned on, and that's all it has to do. True, it (very) bad programming right now, but it does (well, it does now!) the trick.
b) if it would play in a JSP (or HTML page for that matter) it would have no effect. The idea is to sound the alarm when the internet connection to the machine is gone. The machine is 10 meters away from me, but I cannot see who is touching it and who is doing what. By using this servlet, an alarm will sound, and the only (well....my prefered actually) solution to stop the alarm is to replug the cable.
c) True, but what's in a name? (That which we call a rose By any other word would smell as sweet.)
Thanks again for your (both of you) help,
Greetings, Erik
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Sound in Servlet