Forum  General Visual ...  How do I...?  Playing Sound on IIS not working?
Previous Previous
 
Next Next
New Post 11/21/2011 6:01 AM
  mafKomutel
5 posts
No Ranking


Playing Sound on IIS not working? 

Well I have a little issue with my program. When I run my code on the web developpement server trough visual studio, my .wav sound succesfully play each time I call my function but when I pusblish it on my localhost IIS the sound is not playing? I have looked my path again and again and the path is dynamic and static to the local resource folder so I dont see why it is not playing. The rest of the code work great, but yea. No sound o.O

Any help?

 

private void PlayWav()
{
            System.Media.SoundPlayer player = new System.Media.SoundPlayer(VWGContext.Current.Server.MapPath("~\\Resources\\UserData\\bipsound.wav"));
            player.Play();
            System.Media.SystemSound sound = System.Media.SystemSounds.Beep;
            sound.Play();
}

 
New Post 11/21/2011 1:46 PM
  palli
11824 posts
1st Level Poster




Re: Playing Sound on IIS not working? 

Hi mafKomutel,

Please be aware of that you are using a seperated server-side and client-side code. The code you posted is server-side code, so while you are running your application within your Visual Studio development environment, both client-side and server-side are on the same machine and, as you say, you can hear the sound. When you deploy your application, this part of the code is running on the server, so if the sound would play at all, it would play on the server. I am sure there are some restrictions placed on the server process as to what API it can access, so by default it may not even play at the server.

You may find this article here interesting on the differences between Windows Forms and Visual WebGui.

What you will need to get it to play on your client, is a plugin or an ActiveX (if using IE) that can play this type of files. You can find similar solutions for video playing on our ObjectBox article here.

Please let me know if I'm completely misunderstanding your question, or if you need further help on this subject.

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 1/9/2012 7:13 AM
  mafKomutel
5 posts
No Ranking


Re: Playing Sound on IIS not working? 
Modified By mafKomutel  on 1/9/2012 11:25:57 AM)

Hi Palli, I understand that playing sound from IIS is not directly possible since the sound itself is not embed into the client side. So I had to improvise some walkround for this.

The first thing I tried was to add an HTMLBOX into my application, then put some html & javascript into it and call this javascript function from the main code.

____________________________________________________________________________________________________

The code (mostly for IE):

htmlBox1.Html = "<html><head><script type='text/javascript'>"+
                            "function EvalSound() {var thissound=document.getElementById('sound1'); thissound.Play();}" +
                            "</script></head><body><embed src='/../Resources/UserData/bipsound.wav' autostart='false' width=1 height=1 id='sound1' enablejavascript='true'>" +
                            "</body></html>"

then in my code I call the js function like the following.

this.InvokeMethodWithId("window.frames[0].window.EvalSound");

____________________________________________________________________________________________________

Again the code work on the developement server but when I publish it on IIS, I cant still hear any sound. So I am wondering if It could be a path problem? Like when the code is compiled or something, or am I really missing logic or just misunderstanding something.

Thank you!

 

 
New Post 1/9/2012 1:00 PM
  palli
11824 posts
1st Level Poster




Re: Playing Sound on IIS not working? 

Hi mafKomutel,

My guess, and it's only a guess, is that you deployed your application to IIS, but not to the root folder. If so, then the Url to your application is not "/", but rather "/yourVirtualFolder/".

If this is true, then the following code shold help:

            string strPath = Context.HttpContext.Request.ApplicationPath;
            if (! strPath.EndsWith("/"))
            {
                strPath+= "/";
            }
            htmlBox1.Html = "<html><head><script type='text/javascript'>" +
                            "function EvalSound() {var thissound=document.getElementById('sound1'); thissound.Play();}" +
                            "</script></head><body><embed src='" + strPath + "Resources/UserData/bipsound.wav' autostart='false' width=1 height=1 id='sound1' enablejavascript='true'>" +
                            "</body></html>";

In this case, I used an inherited HtmlBox using the following code to trigger the EvalSound() method:

            this.InvokeScript(string.Format("document.getElementById('TRG_{0}').contentWindow.EvalSound();", this.ID));

Hope this helps,

Palli

 


Páll Björnsson - Visual WebGui support team - Email: support@visualwebgui.com
 
New Post 1/12/2012 9:33 AM
  mafKomutel
5 posts
No Ranking


Re: Playing Sound on IIS not working? 

Thanks Palli, the piece of code you provided is working good! I found out my mistake to, so thanks alot for your time!

Really appreciated!

-Marc

 
Previous Previous
 
Next Next
  Forum  General Visual ...  How do I...?  Playing Sound on IIS not working?
Assessment Bottom
.NET Web, Cloud and Mobile application delivery platform | Sitemap | Terms of Use | Privacy Statement | Copyright © 2005-2011 Visual WebGui®       Visual WebGui weblog on ASP.NET Visual WebGui Group on LinkedIn Visual WebGui updates on Twitter Visual WebGui Page on Facebook Visual WebGui YouTube Channel Visual WebGui Platform News RSS