1

I create this web application that provides sound whenever the number in the window changes. When I run my application in Visual Studio, The sound perfectly works but when I open my web with IIS 7, the sound doesn't work anymore.

What causes this? And How can I solve it?

I'm using ASP.Net by the way.

thanks for immediate response.

This is the code that i use

public void providesound()

{

 System.Reflection.Assembly a =System.Reflection.Assembly.GetExecutingAssembly();
 System.IO.Stream s = a.GetManifestResourceStream("~/sound/beep.wav");
 SoundPlayer player = new SoundPlayer(s);
 player.Play(); 

}
Damien_The_Unbeliever
  • 234,701
  • 27
  • 340
  • 448
Kuriyama Mirai
  • 867
  • 5
  • 17
  • 37
  • Where's the code that plays the sound? I suspect that you've used an inappropriate API that is attempting to play the sound on the web server rather than through the browser. – Damien_The_Unbeliever Apr 25 '14 at 08:22
  • The sound is on the web code itself. What should I do about that? – Kuriyama Mirai Apr 25 '14 at 08:47
  • I have no idea what you mean by "on the web code itself" - this question would be improved immensely if you actually *showed* us some of the (relevant) code. – Damien_The_Unbeliever Apr 25 '14 at 08:49
  • I've been using this code public void providesound() { System.Reflection.Assembly a = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream s = a.GetManifestResourceStream("~/sound/beep.wav"); SoundPlayer player = new SoundPlayer(s); player.Play(); } – Kuriyama Mirai Apr 25 '14 at 08:57

2 Answers2

2

Since the sound is playing in your dev environment the only reason I can think of for sound not playing when deployed in IIS is that; your IIS is not configured to send the sound file across to the client. In simple words if you have a sound file say with .wav extenstion, in IIS under MIME Types of you website see if you have an entry for this extension. If not the following link can help you create the MIME entry:

http://technet.microsoft.com/en-us/library/cc725608(v=ws.10).aspx

I believe this would solve your problem, but if not then you should post the code as asked by Damien and also add the details about how you are publishing your site (step by step).

Edit 1:

Looking at the code that you are using I dont think you can make the sound work that way on your client. here are two link refer them: asp.net SoundPlayer not playing from server , How to run a .wav in client. ASP.NET

Hope this helps.

Community
  • 1
  • 1
Shashank Chaturvedi
  • 2,756
  • 19
  • 29
1

I'm able to accomplish this task by creating a Javascript

 function EvalSound(soundobj)
 {
         var thissound = document.getElementById(soundobj);
         thissound.play();
 }
 <audio id="audio1" src="Sound/beep.wav" controls preload="auto" autobuffer HIDDEN=true >

and in my .cs

 public void CreateSound()
 {

        System.Text.StringBuilder sb = new System.Text.StringBuilder();
        sb.Append(@"<script language='javascript'>");
        sb.Append(@"EvalSound('audio1');");
        sb.Append(@"</script>");
        System.Web.UI.ScriptManager.RegisterStartupScript(this, this.GetType(),     "JCall1", sb.ToString(), false);

 }

You can add the CreateSound() in Button_Click.

Kuriyama Mirai
  • 867
  • 5
  • 17
  • 37