• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Sound in Servlet

 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13055
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 374
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
Erik Pragt
Ranch Hand
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic