最近做了一个简单的播放器,使用的是DirectSound,但发现只能播放wav格式的音频文件。怎么样才能播放MP3呢(不使用media player等方法)谢谢各位了
解决方案 »
- c#静态类中如何处理this
- DataGridViewImageColumn怎么动态添加图片?
- C# 子窗体向主窗体的控件传值问题!
- 文件传输问题
- 100分解决:水晶报表中如何动态改变图表
- 我说我的兄弟姐妹们啊,快来帮帮忙啊。小弟我急死了。 在C#中,怎样调用也可以说是直接弹出 OutLook 发信窗口,并自动添加一个附件。
- 怎么无法向数据库添加数据
- Matlab 混编
- 大家来看看,帮帮忙呀?string 到decimal的转换???
- 由于具体程序运行时间较长 想要显示个窗口给用户 让用户不要以为是程序死机或停止了
- 获取图片Exif信息。转码时出现的问题?请路过看看。。。
- ListView 中设置每一行前的项目符号
http://download.csdn.net/source/1010585
public class APIClass
{
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetShortPathName(string lpszLongPath, string shortFile, int cchBuffer);
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
public static extern int mciSendString(string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback);
}
public class Mp3Helper
{
//播放
public static void Play(string strFileName)
{
string buf = "";
buf = buf.PadLeft(128, ' ');
strFileName = "open " + Convert.ToChar(34) + strFileName + Convert.ToChar(34) + " alias media";
APIClass.mciSendString(strFileName, buf, buf.Length, 0); //初始化音频文件
APIClass.mciSendString("play media", buf, buf.Length, 0); //播放音频文件 } //关闭
public static void Stop()
{
APIClass.mciSendString("close media", "", 0, 0);
}
//暂停
public static void Pause()
{
APIClass.mciSendString("pause media", "", 0, 0);
}
}
public class Information
{
//总时间
public static int GetMp3Lenth()
{
string durLength = "";
durLength = durLength.PadLeft(128, Convert.ToChar(" "));
APIClass.mciSendString("status media length", durLength, durLength.Length, 0);
durLength = durLength.Trim(); if (string.IsNullOrEmpty(durLength)) return 0; else return Convert.ToInt32(durLength) / 1000;
}
//当前播放位置
public static int CurrentPosition()
{
string buf = "";
buf = buf.PadLeft(128, ' ');
APIClass.mciSendString("status media position", buf, buf.Length, 0);
buf = buf.Trim();
if (string.IsNullOrEmpty(buf))
return 0;
else
return (int)(Convert.ToDouble(buf)) / 1000;
}
//进度控制
public static bool SetProcess(int process)
{
bool result = false;
string MciCommand = string.Format("seek media to {0}", process);
int RefInt = APIClass.mciSendString(MciCommand, process.ToString(), 0, 0);
APIClass.mciSendString("play media", null, 0, 0);
if (RefInt == 0)
{
result = true;
} return result;
}
//声音控制
public static bool SetValume(int Valume)
{
bool result = false;
string MciCommand = string.Format("setaudio media volume to {0}", Valume);
int RefInt = APIClass.mciSendString(MciCommand, null, 0, 0);
if (RefInt == 0)
{
result = true;
} return result;
}