In this article I will explain with an example, how to use HTML5 Audio Player in ASP.Net MVC.
Audio Location
The Audio file is stored in a Files folder within the Website project.
Controller
The Controller consists of the following Action method.
Action method for handling GET operation
Inside this Action method, simply the View is returned.
public class HomeController : Controller
{
public ActionResult Index()
{
return View();
}
}
View
The View consists of an HTML5 Audio Player element.
The HTML5 Audio Player element has the following properties:
controls – It displays the control buttons such as Play Pause, Volume, etc. in the HTML5 Audio Player.
type – It specifies the media type i.e. MIME type of the media.
src – It is the URL of the Audio.
@{
Layout = null;
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Index</title>
</head>
<body>
<audio controls="controls">
<source src="Files/Kalimba.mp3" type="audio/mpeg" />
</audio>
</body>
</html>
Screenshot
Browser Compatibility
* All browser logos displayed above are property of their respective owners.
Demo
Downloads