由於需要即時讀取影音檔案(mp3、wma、wmv …)播放時間長度的功能,搜尋到的結果有:
顯然第 3 種方案見效最快,立即動手:
① 參考 Shell12 底層介面 c:\Windows\system32\shell32.dll,VS 自動轉換成 Interop.Shell32.dll(註:64 位系統與 32 位系統生成的 Interop.Shell32.dll 不同)
② 編碼讀取播放時間長度:
/// <summary>
/// 獲取媒體播放時間長度,格式 00:00:00。
/// </summary>
/// <param name="path">媒體路徑</param>
/// <returns>播放時間長度</returns>
public static string GetMediaDuration(this string path)
{
try
{
Shell32.Shell shell = new Shell32.ShellClass();
Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
Shell32.FolderItem folderItem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
return folder.GetDetailsOf(folderItem, 21);
}
catch (Exception ex)
{
ex.Error();
return null;
}
}