添加声音的代码
来源:互联网 发布:阿唯得旗舰店淘宝 编辑:程序博客网 时间:2024/05/17 08:14
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等
using System.Runtime.InteropServices;
public static uint SND_ASYNC = 0x0001;
public static uint SND_FILENAME = 0x00020000;
[DllImport("winmm.dll")]
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);
}
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 (axWindowsMediaPlayer1.playState == WMPLib.WMPPlayState.wmppsMediaEnded)
{
Thread thread = new Thread(new ThreadStart(PlayThread));
thread.Start();
}
}
private void PlayThread()
{
axWindowsMediaPlayer1.URL = @"E:/Music/SomeOne.avi";
axWindowsMediaPlayer1.Ctlcontrols.play();
}
MCI Command String和Windows Media Player都有非常丰富的功能接口,这里不能一一介绍,可以参考MSDN中的具体描述.
- 添加声音的代码
- 实现声音开关的代码
- 实现声音开关的代码
- untiy3d声音及多个声音的添加
- C#添加声音
- android添加开机声音
- unity添加声音方法
- 添加3D声音
- Unity基础,添加声音
- 添加按钮声音 播放声音
- JFrame 声音代码
- 播放声音代码
- cocos2d播放声音代码
- 一个控制声音的程序(代码如下:)
- swift的代码教程-ios简单声音类(SoundOp)
- swift的代码教程-ios简单声音类(SoundOp)
- 推送时,播放震动声音不停止的代码
- mp4网页播放代码,有声音无图像的解决办法~
- System.Web.Hosting.HostingEnvironmentException: 访问 IIS 元数据库失败
- jsp+tomcat+mysql和sevlet和javabean配置全过程
- __cdecl __fastcall与 __stdcall
- opencv-IplImage结构图像画到HDC上
- 第一次
- 添加声音的代码
- 深入体会__cdecl与__stdcall
- win32下handle转化为HBITMAP
- opencv-IplImage结构图像画在hdc上
- 熊猫眼啦!头晕得写不鸟程序啦!来谈谈我已经过大半的大学生活吧
- opencv-Win32下HBITMAP格式图像 Convert to为opencv下 IplImage
- 设计网站需要思考的5个目标
- Java注解
- 这就叫重新来--1