如何获得一个音乐文件的播放长度? 用axWindowsMediaPLayer的确可以获得当前音乐的播放长度,但我想把很多歌曲的长度记录在listbox里面,每首歌都要放进去axplayer里面一次?太麻烦了吧?音乐的文件头有没有记录歌曲的播放长度的?比如MP3和WMA 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 using System.IO; using Microsoft.Win32; // API 宣告 [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)] public static extern int mciSendString( string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback); // 取得多媒體檔案長度 private long GetMediaLen(string File) { long RetVal = 0; string key = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions"; RegistryKey RegKey = Registry.LocalMachine.OpenSubKey(key); string FileExt = Path.GetExtension(File).Replace(".", ""); string tp = RegKey.GetValue(FileExt, "MPEGVideo").ToString(); RegKey.Close(); string tm = new string((char)0, 128); if (mciSendString("open \"" + File + "\" type " + tp + " alias Media", null, 0, 0) == 0) { if (mciSendString("status Media length", tm, tm.Length, 0) == 0) { tm = tm.Trim((char)0); if (!string.IsNullOrEmpty(tm)) RetVal = Convert.ToInt64(tm) / 1000; } mciSendString("close Media", null, 0, 0); } return RetVal; } 见鬼,再来~using System.IO; using Microsoft.Win32; // API 宣告 [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)] public static extern int mciSendString( string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback); // 取得多媒體檔案長度 private long GetMediaLen(string File) { long RetVal = 0; string key = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions"; RegistryKey RegKey = Registry.LocalMachine.OpenSubKey(key); string FileExt = Path.GetExtension(File).Replace(".", ""); string tp = RegKey.GetValue(FileExt, "MPEGVideo").ToString(); RegKey.Close(); string tm = new string((char)0, 128); if (mciSendString("open \"" + File + "\" type " + tp + " alias Media", null, 0, 0) == 0) { if (mciSendString("status Media length", tm, tm.Length, 0) == 0) { tm = tm.Trim((char)0); if (!string.IsNullOrEmpty(tm)) RetVal = Convert.ToInt64(tm) / 1000; } mciSendString("close Media", null, 0, 0); } return RetVal; } this.axWmp.currentMedia.durationString; 谢谢了,不过API对我来说很陌生,有没有普通点的方法呢? study study studyup up up 建议你不要学C#,去学C++吧,可能可以不用API。 请教 背景图片怎么随显示器大小而变啊 问大家一个.net的超技术的问题(分不是问题) 求个思路100分 开发项目的时候你有用到第三方控件吗? 请问如何对DataTable内的行组rows进行排序? 关于自己开发插件的问题 请教 新论坛完成,请大家给点建议,帮忙找点Bug 在window98中如何正确的安装.net(安装后的.net要正确无误的)? 请问哪里有比较系统介绍C#的网站? 版主,急问数字分段取值显示 有关JSON解析的问题
using System.IO;
using Microsoft.Win32;
// API 宣告 [DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)] public static extern int mciSendString( string lpstrCommand, string lpstrReturnString, int uReturnLength, int hwndCallback); // 取得多媒體檔案長度
private long GetMediaLen(string File) {
long RetVal = 0;
string key = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions";
RegistryKey RegKey = Registry.LocalMachine.OpenSubKey(key);
string FileExt = Path.GetExtension(File).Replace(".", "");
string tp = RegKey.GetValue(FileExt, "MPEGVideo").ToString();
RegKey.Close(); string tm = new string((char)0, 128);
if (mciSendString("open \"" + File + "\" type " + tp + " alias Media", null, 0, 0) == 0)
{
if (mciSendString("status Media length", tm, tm.Length, 0) == 0) {
tm = tm.Trim((char)0);
if (!string.IsNullOrEmpty(tm)) RetVal = Convert.ToInt64(tm) / 1000;
}
mciSendString("close Media", null, 0, 0);
}
return RetVal;
}
using Microsoft.Win32;
// API 宣告
[DllImport("winmm.dll", EntryPoint = "mciSendString", CharSet = CharSet.Auto)]
public static extern int mciSendString(
string lpstrCommand,
string lpstrReturnString,
int uReturnLength, int hwndCallback); // 取得多媒體檔案長度
private long GetMediaLen(string File) {
long RetVal = 0;
string key = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\MCI Extensions";
RegistryKey RegKey = Registry.LocalMachine.OpenSubKey(key);
string FileExt = Path.GetExtension(File).Replace(".", "");
string tp = RegKey.GetValue(FileExt, "MPEGVideo").ToString();
RegKey.Close(); string tm = new string((char)0, 128);
if (mciSendString("open \"" + File + "\" type " + tp + " alias Media", null, 0, 0) == 0)
{
if (mciSendString("status Media length", tm, tm.Length, 0) == 0) {
tm = tm.Trim((char)0);
if (!string.IsNullOrEmpty(tm)) RetVal = Convert.ToInt64(tm) / 1000;
}
mciSendString("close Media", null, 0, 0);
}
return RetVal;
}
建议你不要学C#,去学C++吧,可能可以不用API。