C#winform 怎么播放amr音频文件
1个回答
展开全部
使用MCI Command String多媒体设备程序接口播放mp3,avi等。
这种方法很好用。
下面的类传入音乐名(路径)可以完成音乐播放,循环播放和停止。
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); //停止播放
}
}
这种方法很好用。
下面的类传入音乐名(路径)可以完成音乐播放,循环播放和停止。
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); //停止播放
}
}
微测检测5.10
2023-05-10 广告
2023-05-10 广告
您好!建议咨 深圳市微测检测有限公司,已建立起十余个专业实验室,企业通过微测检测就可以获得一站式的测试与认 证解决方案;(EMC、RF、MFi、BQB、QI、USB、安全、锂电池、快充、汽车电子EMC、汽车手机互 联、语音通话质量),认证遇...
点击进入详情页
本回答由微测检测5.10提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询