2024年3月28日发(作者:)

1.播放系统事件声音

2.使用layer播放wav

3.使用MCI Command String多媒体设备程序接口播放mp3,avi等

4.使用axWindowsMediaPlayer的COM组件来播放

1.播放系统事件声音

();

();

();

();

();

2.使用layer播放wav

layer sp = new SoundPlayer();

ocation = @"D:/";

oping();

3.使用MCI Command String多媒体设备程序接口播放mp3,avi等

using pServices;

public static uint SND_ASYNC = 0x0001;

public static uint SND_FILENAME = 0x00020000;

[DllImport("")]

public static extern uint mciSendString(string lpstrCommand,

string lpstrReturnString, uint uReturnLength, uint hWndCallback);

public void Play()

{

mciSendString(@"close temp_alias", null, 0, 0);

mciSendString(@"open ""E:/Music/青花瓷.mp3"" alias temp_alias", null,

0, 0);

mciSendString("play temp_alias repeat", null, 0, 0);

}

关于mciSendString的详细参数说明,请参见MSDN,或是

/psongchao/archive/2007/01/19/

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循环播放列表中的媒体文件?

假设我们有一个播放列表,下面的代码可以实现自动循环播放

private void axWindowsMediaPlayer1_PlayStateChange(object sender,

AxWMPLib._WMPOCXEvents_PlayStateChangeEvent e)

{

if (ate ==

ediaEnded)

{

Thread thread = new Thread(new ThreadStart(PlayThread));

();

}

}

private void PlayThread()

{

= @"E:/Music/";

();

}

MCI Command String和Windows Media Player都有非常丰富的功能接口,这里不