读书人

VC#2003中 API做的音乐播放如何停止

发布时间: 2011-12-26 23:09:58 作者: rapoo

VC#2003中 API做的音乐播放,怎么停止?
代码如下:
[DllImport("winmm.dll")]
public static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2);

[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path,StringBuilder shortPath, Int32 shortPathLength);

private static void playMusic(string name)
{
StringBuilder shortpath = new StringBuilder(80);
int result = GetShortPathName(name, shortpath, shortpath.Capacity);
name = shortpath.ToString();
string buf = string.Empty;

mciSendString("play "+name,buf, buf.Length, 0);
}


private void Form1_Load(object sender, System.EventArgs e)
{

}

private void radio_music1_CheckedChanged(object sender, System.EventArgs e)
{


playMusic("忧伤还是快乐.mp3");
}

private void radio_music2_CheckedChanged(object sender, System.EventArgs e)
{

playMusic("飘雪.mp3");
}
页面有两个radiobutton, 选第一个时第一个歌曲播放,选第二个时第一个歌曲停止,第二个播放。播放该怎样停止???

[解决办法]
一,播放
mciSendString("play movie",buf,sizeof(buf),NULL);
  二,如果想全屏播放:
  mciSendString("play movie fullscreen",buf,sizeof(buf),NULL);
  三,暂停播放。
  mciSendString("pause movie",buf,sizeof(buf),NULL);
  四,停止播放。
  mciSendString("close movie",buf,sizeof(buf),NULL);
  五,得到所播放文件的长度。
  char sPosition[256];long lLength;
  ciSendString("Status movie length", sPosition, 255,0);lLength=strtol(sPosition, NULL, 10);
  其中lLength就是所播放文件的长度。

[解决办法]
建议你下个media的dll,这个比调用上面哪些api函数要好用的多!

读书人网 >C#

热点推荐