using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Runtime.InteropServices; namespace audio1 { public partial class Form1 : Form { private string Pcommand; private bool isOpen; [DllImport("winmm.dll")] private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback); public void Close() { Pcommand = "close MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen=false; } public void Open(string sFileName) { Pcommand = "open \"" + sFileName + "\" type mpegvideo alias MediaFile"; mciSendString(Pcommand, null, 0, IntPtr.Zero); isOpen = true; } public void Play(bool loop) { if(isOpen) { Pcommand = "play MediaFile"; if (loop) Pcommand += " REPEAT"; mciSendString(Pcommand, null, 0, IntPtr.Zero); } } public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { openFileDialog1.Filter = "|*.mp3"; openFileDialog1.ShowDialog(); textBox1.Text = openFileDialog1.FileName; Open(textBox1.Text); } private void button2_Click(object sender, EventArgs e) { Play(false); } private void button3_Click(object sender, EventArgs e) { Close(); } } }