聲明這是 微軟論壇上看的. 我看了很多人都在尋找C# mciSendString()迴圈播放音樂
學英語重要呀。
using System;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows.Forms;
namespace PlayMp3WithWindow
{
public partial class Form1 : Form
{
public const int MM_MCINOTIFY = 0x3B9; //這是聲明 播完音樂 mciSendString()向系統發送的指令
[DllImport("winmm.dll")]
private static extern long mciSendString(string command,
StringBuilder returnString,
int returnSize,
IntPtr hwndCallback);
public Form1()
{
InitializeComponent();
PlaySong(@"123.mp3"); // when complete callback to DefWndProc
//歌曲路徑,開始就播放這個
}
protected override void DefWndProc(ref Message m)
{
base.DefWndProc(ref m);
if (m.Msg == MM_MCINOTIFY) //判斷指令是不是MM_MCINOTIFY
//當歌曲播完 mciSendString()向系統發送的MM_MCINOTIFY指令
{
PlaySong(@"456.mp3");//播完就自動播放這個。。。
}
}
public void PlaySong(string file)
{
mciSendString("close media", null, 0, IntPtr.Zero);//關閉
mciSendString("open \"" + file + "\" type mpegvideo alias media", null, 0, IntPtr.Zero);
//開啟 file 這個路徑的歌曲 " ,type mpegvideo是檔案類型 , alias 是將檔案別名為media
mciSendString("play media notify", null, 0, this.Handle);//播放
}
}
}
seo:http://greatverve.cnblogs.com/archive/2011/06/24/mciSendString.html