How do I play an mp3 audio online on a c# Web Application?
If you open a documentation page for SoundPlayer (https://msdn.microsoft.com/en-us/library/system.media.soundplayer(v=vs.110).aspx) 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: https://github.com/filoe/cscore, https://www.ambiera.com/irrklang/, https://github.com/naudio/NAudio 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.
asp.net playing sound file from code behind
I'd try pulling it using Server.MapPath
System.Web.HttpContext.Current.Server.MapPath(path);
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>
</audio>
In code behind check browser and set the src to audio tag if its html5 supportive else to object
if (status !="DN")
{
if(!html5browser)
audiofile.attributes.add("data","path/audiofile");
else
audiotag.attributes.add("src","path/audiofile");
}
Using Response.write
Response.Write("<embed height='0' width='0' src='path/audiodile' />");
Related Topics
Difference Between Ienumerable Count() and Length
Is There a Complete Iequatable Implementation Reference
Prevent C# App from Process Kill
Get the Sourcecontrol of a Dropdownmenu
How to Expand a String That Contains C# Literal Expressions at Runtime
How to Deploy a .Net Application That Uses Odac Without Installing the Whole Component to the User
Loop Through All Controls on ASP.NET Webpage
I Have to Access/Commit/Update Svn Repository in Wpf Application Using Svn API or Libraries
JSON Deserialization - Map Array Indices to Properties with JSON.Net
Singleton Httpclient VS Creating New Httpclient Request
Use the Dynamic Keyword/.Net 4.6 Feature in Unity
Ms Chart Rectangular Annotation Width in Percent and Not Pixel
Digital Signature in C# Without Using Bouncycastle
How to Click a Button in a Webbrowser Control
Get All Associate/Composite Objects Inside an Object (In Abstract Way)