How to Play a Sound in an ASP.NET Web Page

How do I play an mp3 audio online on a c# Web Application?

If you open a documentation page for SoundPlayer ( you'll read, that this class "Controls playback of a sound from a .wav file."
This means, that if you want to play .mp3 you need something different, something capable of doing the job. There are a lot of options, to name a few:,, and many more others.

Another thing is that you are working with ASP.Net. This means that what you probably want is to play music on the client's machine, not at your server like you do now. If this is the case, then this is a completely different story, no .Net sound libraries would help you, you need to learn what is the difference between client-side and server-side execution first, until you do that you don't go anywhere. playing sound file from code behind

I'd try pulling it using Server.MapPath


How to play/pause a wav file in asp page

It's not pretty, but I managed to terminate the sound like this.

function StopSound()
if (soundObject != null) {

soundObject.setAttribute("src", "");
soundObject = null;


how to run a notification sound (bell) in website in the if condition in c#

use <object> or <embed> html tags and make these as server control, runat="server" and give them Ids.

<object id="audiofile" runat="server" data=""></object>
Or HTML5 tag

<audio id ="audioTag" runat="server" src="">
<p>This browser does not support audio.</p>

In code behind check browser and set the src to audio tag if its html5 supportive else to object

     if  (status !="DN")

Using Response.write

Response.Write("<embed height='0' width='0' src='path/audiodile' />");

Related Topics

Leave a reply