[C#]使用WindowsAPI中的mciSendString函式播放音乐
2012-10-18 10:06
357 查看
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Media; using System.Runtime.InteropServices; // 命名空間提供各種支援COM Interop 和平台叫用服務的成員 namespace WindowsApplication17 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } [DllImport("winmm.dll")] public static extern int mciSendString(string m_strCmd, string m_strReceive, int m_v1, int m_v2); [DllImport("Kernel32", CharSet = CharSet.Auto)] static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength); /// <summary> /// 使用mciSendString播放音樂 /// </summary> /// <param name="name">檔案名稱</param> /// <param name="command">命令</param> private static void mciMusic(string name,string command) { StringBuilder shortpath = new StringBuilder(); int result = GetShortPathName(name, shortpath, shortpath.Capacity); name = shortpath.ToString(); string buf = string.Empty; mciSendString(command + " " + name, buf, buf.Length, 0); //播放 } private void btnPlay_Click(object sender, EventArgs e) { // 播放 mciMusic(@"01.mp3", "play"); } private void btnPause_Click(object sender, EventArgs e) { // 暫停 mciMusic(@"01.mp3", "pause"); } private void btnStop_Click(object sender, EventArgs e) { // 停止 mciMusic(@"01.mp3", "stop"); } } }
参考网址:http://www.dotblogs.com.tw/chou/archive/2009/06/30/9051.aspx
本人网站 http://www.lorna.com.cn
相关文章推荐
- C#中使用Windows Media Player播放音乐的方法
- C#、VB.NET 使用System.Media.SoundPlayer播放音乐
- C#/.NET使用MediaPlayer控件播放MP3等音乐文件
- 使用C#调用win32 mciSendCommand 播放音乐
- C#、VB.NET 使用System.Media.SoundPlayer播放音乐
- C# winform使用系统API播放音乐(非调用控件)
- C#、VB.NET 使用System.Media.SoundPlayer播放音乐
- C#使用MediaPlayer控件播放MP3等音乐文件
- 【Espruino】NO.16 使用VS1003播放音乐
- win mobile 5播放mp3音乐的方法(2)--libmad库的使用篇
- 使用JMF实现音乐播放(java多媒体编程)
- 使用libvlc简单的播放一首本地音乐文件
- Android 使用mediaplayer播放res/raw文件夹中的音乐的实例
- 【Android Dev Guide - 04】 - Media - 学习使用MediaPlayer播放音乐
- c#使用System.Media.SoundPlayer播放资源文件中的wav文件
- 树莓派3b使用蓝牙当做A2DPsink端播放音乐
- 使用 AudioManager 类在 XNA 中播放控制声音和音乐,WPXNA(五)
- 使用libvlc播放音乐,实时获取位置、播放状态、时长,播放httpURL
- c# 播放音乐
- Android多媒体开发 音乐播放(加带进度条、时间显示)以及使用SoundPool播放音效