日期:2014-05-17  浏览次数:21002 次

C# winform 如何播放amr音频文件
目前2种思路。
一个是用Windows media play 播放,需要装一个20M的解码包才可以播放。
二是调用第三方程序(以前用过ffmpeg 不知道支不支持amr 到mp3?求推荐) 把amr转mp3,然后在用wmp播放。

还有什么最简单的方法没?求解。万分感谢。

------解决方案--------------------
如果有免费的解压包,使用解压包的方法不错,安装一次即可,也不用再次转换了
------解决方案--------------------
使用MCI Command String多媒体设备程序接口播放mp3,avi等。
这种方法很好用。
下面的类传入音乐名(路径)可以完成音乐播放,循环播放和停止。
C# code

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
------解决方案--------------------
探讨

win7装个win7codecs这个Windows media play就可以播放amr了。
XP还没去试,应该可以找到对应的解码器。

------解决方案--------------------
是不是可以调用API的方式 异步播放。
好像可以 你找找资料。