C#中播放背景音乐几种的方法
来源:互联网 发布:c语言 long int 编辑:程序博客网 时间:2024/05/22 03:52
最经在写winform程序,其中有用到播放背景音乐
关于mciSendString的详细参数说明,请参见MSDN,或是 http://blog.csdn.net/psongchao/archive/2007/01/19/1487788.aspx
特此收集了一些网上的教程:
1、调用非托管的dll
- using System.Runtime.InteropServices; //DllImport命名空间的引用
- class test //提示音
- {
- [DllImport("winmm.dll")]
- public static extern bool PlaySound(String Filename,int Mod,int Flags);
- public void Main()
- {
- PlaySound(@"d:/qm.wav",0,1); //把1替换成9,可连续播放
- }
- }
2、播放系统自带声音
- 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();
3、使用System.Media.SoundPlayer播放wav
- System.Media.SoundPlayer sp = new SoundPlayer();
- sp.SoundLocation = @"D:\10sec.wav";
- sp.PlayLooping();
4、使用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);
- }
5、使用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();
- }
阅读全文
0 0
- C#中播放背景音乐几种的方法
- C#中播放背景音乐几种的方法
- C#播放背景音乐的五种方法
- 网页中插入背景音乐的几种方法
- C#播放背景音乐常用的四种方式
- C#播放背景音乐常用的四种方式(转载)
- C#播放背景音乐常用的四种方式
- C#播放背景音乐常用的四种方式
- C#播放背景音乐常用的四种方式
- C#播放背景音乐常用的四种方式
- C#播放背景音乐
- MFC工程中播放背景音乐的实现
- Spritekit中播放背景音乐
- VC++中播放声音文件的几种不同方法
- 如何使用C#播放背景音乐
- 如何使用C#播放背景音乐
- android 背景音乐的播放
- Android中添加背景音乐的两种方法
- java:具有返回值的函数,没有返回值的函数及三目运算符的运用
- java线程池
- Android CoordinatorLayout和Behavior的源码分析(二)
- 链表倒数第n个节点
- Python列表
- C#中播放背景音乐几种的方法
- 第一次开通这个博客
- tf.split函数的用法
- 枚举算法
- 二分贪心-B
- META-INF方式多渠道打包提示安装找不到安装证书
- Android CoordinatorLayout和Behavior的源码分析(三)
- laravel Socialite Providers 实现第三方登录
- Hangman Judge (UVA-489)