C#如何计算一个声音文件的播放时间有多长?
来源:百度知道 编辑:UC知道 时间:2024/08/22 06:33:07
谢谢你呀,可是运行的时候Kernel32.dll、winmm.dll这两组件都提示找不到啊?您是不是把这两组件的名称给记错了呀??
使用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 TimeSp