I am having numerous problems with getting the html5 audio control to work in my ASP.NET page. I am using IE11 and finally got the control to work by converting my MP3 to an M4A format. That was a big hurdle in itself. My next thing is to have the music
play when a button is clicked or preferably through an event. The problem is that when I do it through Javascript on a onclientclick or onclick it appears to cause a postback and the music never plays. The music plays fine through the control's play button.
I would even like to fire it off from a C# event as well but can't seem to get my hooks into the audio control. Anyone got this to work in Visual Studio 10 with IE11 and specifying content = "ie=edge". Seems to work fine browsing other sites than my own ASP.NET
website.....
My next thing is to have the music play when a button is clicked or preferably through an event. The problem is that when I do it through Javascript on a onclientclick or onclick it appears to cause a postback and the music never plays.
You could try to use event.preventDefault() method to cancel the default action to prevent button from posting back.
I threw in the towel on HTML5 audio control and IE11 with ASP.NET. Using (below) the following HTML and C# code I got it to work on an ASP.NET website and IE11. Funny thing with the audio control, it always works in Chrome. BTW, I found the right settings
to get the audio control to work in the Visual Studio debugger and I thought I was home free. The problem was it would not work or show at all after the code was actually deployed. Embed was definitely a slam dunk as far as working in IE but I need to piece
together the right setup (below) to do it. Hope this helps someone....
Member
2 Points
30 Posts
Using html audio control in ASP.NET page generated by Visual Studio
Jan 12, 2016 07:38 PM|petey100|LINK
I am having numerous problems with getting the html5 audio control to work in my ASP.NET page. I am using IE11 and finally got the control to work by converting my MP3 to an M4A format. That was a big hurdle in itself. My next thing is to have the music play when a button is clicked or preferably through an event. The problem is that when I do it through Javascript on a onclientclick or onclick it appears to cause a postback and the music never plays. The music plays fine through the control's play button. I would even like to fire it off from a C# event as well but can't seem to get my hooks into the audio control. Anyone got this to work in Visual Studio 10 with IE11 and specifying content = "ie=edge". Seems to work fine browsing other sites than my own ASP.NET website.....
All-Star
39166 Points
5689 Posts
Microsoft
Re: Using html audio control in ASP.NET page generated by Visual Studio
Jan 13, 2016 06:29 AM|Fei Han - MSFT|LINK
Hi petey100,
You could try to use event.preventDefault() method to cancel the default action to prevent button from posting back.
http://www.w3schools.com/jquery/event_preventdefault.asp
Best Regards,
Fei Han
MSDN Community Support
Please remember to "Mark as Answer" the responses that resolved your issue.
Member
2 Points
30 Posts
Re: Using html audio control in ASP.NET page generated by Visual Studio
Jan 13, 2016 06:27 PM|petey100|LINK
I threw in the towel on HTML5 audio control and IE11 with ASP.NET. Using (below) the following HTML and C# code I got it to work on an ASP.NET website and IE11. Funny thing with the audio control, it always works in Chrome. BTW, I found the right settings to get the audio control to work in the Visual Studio debugger and I thought I was home free. The problem was it would not work or show at all after the code was actually deployed. Embed was definitely a slam dunk as far as working in IE but I need to piece together the right setup (below) to do it. Hope this helps someone....
<script type="text/javascript"> function PlaySong() { document.getElementById("SongSpan").innerHTML= '<embed src="MySong.m4a" hidden="true" autostart="true loop="false" />'; } </script>
<span id="SongSpan"></span>
On my image click event I used this C# code:
Page.ClientScript.RegisterStartupScript(this.GetType(), "CallMyFunction", "PlaySong()", true);