1. 插入一个width,height为0得播放器。并设置自动播放和循环播放为 true
2. using System.Runtime.InteropServices;
[DllImport("winmm.dll")]
public static extern long PlaySound(String fileName,long a,long b);
在事件中添加:
PlaySound("aa.wav",0,0); //aa.wav为声音文件
3. [DllImport("winmm.dll")]
public static extern long mciSendString(string lpstrCommand,string lpstrReturnString,long length,long hwndcallback);
/// <summary>
/// 播放音乐文件
/// </summary>
/// <param name="p_FileName">音乐文件名称</param>
public static void PlayMusic(string p_FileName)
{
try
{
mciSendString(@"close " +p_FileName ," ",0,0);
mciSendString(@"open " + p_FileName," ",0,0);
mciSendString(@"play " + p_FileName ," ",0,0);
}
catch
{
}
}
/// <summary>
/// 停止当前音乐播放
/// </summary>
/// <param name="p_FileName">音乐文件名称</param>
public static void StopMusic(string p_FileName)
{
try
{
mciSendString(@"close " + p_FileName," ",0,0);
}
catch{}
}
另外注意,由于文件路径和文件名中可能有空格,因此,文件名要用引号引起来,如:
filename="\"c:\\programe files\\a.mp3\"";