0

I have a page that calculates certain values coming from a web service.

I would like to be able to play different sounds based on the calculation results. There must be no interaction from the user (click button to play).

The SoundPlayer class seems like what I need but I believe there is an error with the relative path because if I specify the absolute path it does work.

System.Media.SoundPlayer playthewavfile = new System.Media.SoundPlayer(@"Sounds\sound1.wav");
playthewavfile.Play();

The Sounds folder is in the root of the website.

mantal
  • 1,093
  • 1
  • 20
  • 38
sd_dracula
  • 3,796
  • 28
  • 87
  • 158
  • possible duplicate of [how to play a sound in asp.net web page?](http://stackoverflow.com/questions/12329191/how-to-play-a-sound-in-asp-net-web-page) – Sriram Sakthivel Nov 22 '13 at 09:57
  • check out this resolved thread.. http://stackoverflow.com/questions/187098/cross-platform-cross-browser-way-to-play-sound-from-javascript hope it helps./. – kaushalparik27 Nov 22 '13 at 09:58
  • If I change the path to : `System.Media.SoundPlayer playthewavfile = new System.Media.SoundPlayer(Server.MapPath(@"Sounds\sound1.wav"));` it works but only when running on local dev machine. Once the site is up on IIS it does not. – sd_dracula Nov 22 '13 at 10:04
  • 1
    Because the sound plays serverside. – CodeCaster Nov 23 '13 at 16:34

1 Answers1

0

I'd try pulling it using Server.MapPath

System.Web.HttpContext.Current.Server.MapPath(path);