C#播放背景音乐通常有四种方式:
1.播放系统事件声音
2.使用System.Media.SoundPlayer播放wav
3.使用MCI Command String多媒体设备程序接口播放mp3,avi等
4.使用axWindowsMediaPlayer的COM组件来播放
1.播放系统事件声音
System.Media.SystemSounds.Asterisk.Play(); System.Media.SystemSounds.Beep.Play(); System.Media.SystemSounds.Exclamation.Play(); System.Media.SystemSounds.Hand.Play(); System.Media.SystemSounds.Question.Play(); |
2.使用System.Media.SoundPlayer播放wav
System.Media.SoundPlayer sp = new SoundPlayer(); sp.SoundLocation = @"D:\10sec.wav"; sp.PlayLooping(); |
3.使用MCI Command String多媒体设备程序接口播放mp3,avi等
|
关于mciSendString的详细参数说明,请参见MSDN,或是 http://blog.csdn.net/psongchao/archive/2007/01/19/1487788.aspx
4.使用axWindowsMediaPlayer的COM组件来播放
a.加载COM组件:ToolBox->Choose Items->COM Components->Windows Media Player如下图:
b.把Windows Media Player控件拖放到Winform窗体中,把axWindowsMediaPlayer1中URL属性设置为MP3或是AVI的文件路径,F5运行。
如何使用Windows Media Player循环播放列表中的媒体文件?
假设我们有一个播放列表,下面的代码可以实现自动循环播放
|
MCI Command String和Windows Media Player都有非常丰富的功能接口,这里不能一一介绍,可以参考MSDN中的具体描述.