110,567
社区成员
发帖
与我相关
我的任务
分享
public class PlayMP3
{
/// <summary>
/// 文件地址
/// </summary>
public string FilePath;
/// <summary>
/// 播放
/// </summary>
public void Play()
{
mciSendString("close all", "", 0, 0);
mciSendString("open " + FilePath + " alias media", "", 0, 0);
mciSendString("play media", "", 0, 0);
}
/// <summary>
/// 暂停
/// </summary>
public void Pause()
{
mciSendString("pause media", "", 0, 0);
}
/// <summary>
/// 停止
/// </summary>
public void Stop()
{
mciSendString("close media", "", 0, 0);
}
/// <summary>
/// API函数
/// </summary>
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
private static extern int mciSendString(
string lpstrCommand,
string lpstrReturnString,
int uReturnLength,
int hwndCallback
);
}
private void button1_Click(object sender, EventArgs e)
{
PlayMP3 mp3 = new PlayMP3();
//设置要播放的文件
mp3.FilePath = "D:/essence.mp3";
//播放
mp3.Play();
}