C#如何计算一个声音文件的播放时间有多长?
如题.谢谢你呀,可是运行的时候Kernel32.dll、winmm.dll这两组件都提示找不到啊?您是不是把这两组件的名称给记错了呀??...
如题.
谢谢你呀,可是运行的时候Kernel32.dll、winmm.dll这两组件都提示找不到啊?您是不是把这两组件的名称给记错了呀?? 展开
谢谢你呀,可是运行的时候Kernel32.dll、winmm.dll这两组件都提示找不到啊?您是不是把这两组件的名称给记错了呀?? 展开
2个回答
展开全部
使用MCI。
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength);
[DllImport("winmm.dll")]
public static extern int mciSendString(string m_strCmd, StringBuilder m_strReceive, int m_v1, int m_v2);
下面是检查声音文件长度的代码:
StringBuilder shortpath = new StringBuilder(80);
GetShortPathName(@"F:\我的文档\My Music\zhs.mp3", shortpath, shortpath.Capacity);
string name = shortpath.ToString();
StringBuilder buf = new StringBuilder(80);
mciSendString("close all", buf, buf.Capacity, 0);
mciSendString("open " + name + " alias media", buf, buf.Capacity, 0);
mciSendString("status media length", buf, buf.Capacity, 0);
TimeSpan ts = new TimeSpan(0, 0, 0, 0, (int)Convert.ToDouble(buf.ToString().Trim()));
textBox1.Text = ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds + "." + ts.Milliseconds;
[DllImport("Kernel32", CharSet = CharSet.Auto)]
static extern Int32 GetShortPathName(String path, StringBuilder shortPath, Int32 shortPathLength);
[DllImport("winmm.dll")]
public static extern int mciSendString(string m_strCmd, StringBuilder m_strReceive, int m_v1, int m_v2);
下面是检查声音文件长度的代码:
StringBuilder shortpath = new StringBuilder(80);
GetShortPathName(@"F:\我的文档\My Music\zhs.mp3", shortpath, shortpath.Capacity);
string name = shortpath.ToString();
StringBuilder buf = new StringBuilder(80);
mciSendString("close all", buf, buf.Capacity, 0);
mciSendString("open " + name + " alias media", buf, buf.Capacity, 0);
mciSendString("status media length", buf, buf.Capacity, 0);
TimeSpan ts = new TimeSpan(0, 0, 0, 0, (int)Convert.ToDouble(buf.ToString().Trim()));
textBox1.Text = ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds + "." + ts.Milliseconds;
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询