Wednesday, May 25, 2011

How to play audio file in c#

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Media;
using WMPLib; //Add this COM Component Reference to your project

public partial class PlayMusic : System.Web.UI.Page
protected void Page_Load(object sender, EventArgs e)


protected void btnPlayMusic_Click(object sender, EventArgs e)
string _path = "File Path";

//Method 1 using sound player class
SoundPlayer _sm = new SoundPlayer(_path);
//Method 2
Microsoft.VisualBasic.Devices.Audio _mvda = new Microsoft.VisualBasic.Devices.Audio();
_mvda.Play(_path, Microsoft.VisualBasic.AudioPlayMode.Background);

//Method 3 using WindowsMediaPlayer Class
WindowsMediaPlayerClass _wmpc = new WindowsMediaPlayerClass();


No comments:

Post a Comment