C#播放音频文件的四种方式

C#播放音频文件的四种方式


2024年5月22日发(作者:)

C#播放音频文件的四种方式:

1.播放系统事件声音

2.使用layer播放wav

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

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

具体的使用方法:

1.播放系统事件声音

();

();

();

();

();

2.使用layer播放wav

using ;

layer sp = new SoundPlayer();

ocation = @"F:恋爱"; //音频文件路径

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 ""F:恋爱3"" alias temp_alias", null, 0, 0);

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

}

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

这个方法可以识别一般的文件,比较强大!!

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

a.工具箱->组件->(右键)选择项->COM组件->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:";

();

}


发布者:admin,转转请注明出处:http://www.yc00.com/web/1716337940a2727389.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信