声明这是 微软论坛上看的. 我看了很多人都在查找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); // 播放
}
}
}
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