1
2 public class Player
3 {
4 private string _command;
5 private bool isOpen;
6 [DllImport("winmm.dll")]
7 private static extern long mciSendString(string strCommand,StringBuilder strReturn,int iReturnLength, IntPtr hwndCallback);
8
9 public Player()
10 {
11
12 }
13 public void Close()
14 {
15 _command = "close MediaFile";
16 mciSendString(_command, null, 0, IntPtr.Zero);
17 isOpen=false;
18 }
19
20 public void Open(string sFileName)
21 {
22 _command = "open \"" + sFileName + "\" type mpegvideo alias MediaFile";
23 mciSendString(_command, null, 0, IntPtr.Zero);
24 isOpen = true;
25 }
26
27 public void Play(bool loop)
28 {
29 if(isOpen)
30 {
31 _command = "play MediaFile";
32 if (loop)
33 _command += " REPEAT";
34 mciSendString(_command, null, 0, IntPtr.Zero);
35 }
36 }
37
38 }