日期:2014-05-17 浏览次数:21051 次
using System.Runtime.InteropServices; class Music { [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); private void playMusic(string name) { try { StringBuilder shortpath = new StringBuilder(80); int result = GetShortPathName(name, shortpath, shortpath.Capacity); name = shortpath.ToString(); string buf = string.Empty; mciSendString("play " + name, buf, buf.Length, 0); //播放 } catch (Exception ex) { throw ex; } } private void playMusicRepeatly(string name) { try { StringBuilder shortpath = new StringBuilder(80); int result = GetShortPathName(name, shortpath, shortpath.Capacity); name = shortpath.ToString(); string buf = string.Empty; mciSendString("play " + name+" repeat", buf, buf.Length, 0); //播放 } catch (Exception ex) { throw ex; } } public void stopMusic(string name) { StringBuilder shortpath = new StringBuilder(80); int result = GetShortPathName(name, shortpath, shortpath.Capacity); name = shortpath.ToString(); string buf = string.Empty; mciSendString(@"stop "+name, buf, buf.Length, 0); mciSendString(@"close "+name, buf, buf.Length, 0); //停止播放 } }
------解决方案--------------------
看看这个:http://blog.csdn.net/lxiongh/article/details/5350329
使用DirectShow
------解决方案--------------------
还有这个实例:http://www.cnblogs.com/freeliver54/archive/2008/09/17/1292717.html
------解决方案--------------------