C# 获取媒体文件播放时长

引用:

Interop.Shell32.dll

方法:

 1 /// <summary> 
 2         /// 获取媒体文件播放时长 
 3         /// </summary> 
 4         /// <param name="path">媒体文件路径</param> 
 5         /// <returns></returns> 
 6         public static string GetMediaTimeLen(string path)
 7         {
 8             try
 9             {
10                 Shell32.Shell shell = new Shell32.Shell();
11 
12                 //文件路径
13 
14                 Shell32.Folder folder = shell.NameSpace(path.Substring(0, path.LastIndexOf("\\")));
15 
16                 //文件名称
17 
18                 Shell32.FolderItem folderitem = folder.ParseName(path.Substring(path.LastIndexOf("\\") + 1));
19 
20                 if (Environment.OSVersion.Version.Major >= 6)
21                 {
22 
23                     return folder.GetDetailsOf(folderitem, 27);
24 
25                 }
26 
27                 else
28                 {
29 
30                     return folder.GetDetailsOf(folderitem, 21);
31 
32                 }
33             }
34             catch (Exception ex)
35             {
36                 return null;
37             }
38         }
View Code

调用:

1 string itemtimelen = GetMediaTimeLen(path);
2 DateTime t1 = DateTime.Parse(itemtimelen);
View Code

 

转载于:https://www.cnblogs.com/famhuai/p/10564742.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值