日期:2014-05-17  浏览次数:20443 次

如何读取wmv视频文件的总时长
本以为很简单一个需求,结果百度和google都找不到,还请各位高手帮忙了。
问题解决立刻结贴。

------解决方案--------------------
int MovieDuration = (int)this.axWindowsMediaPlayer1.newMedia(mediaFileName).duration; 
该方法能成功获取WMV视频的长度,但AVI就不行,得到的总是为零
------解决方案--------------------
怎样在C#中添加AxWindowsMediaPlayer控件

在VS2005编程环境的“工具箱”中单击右键,选择“选择项”菜单,打开“选择工具箱项”窗口,选择“COM组件”标签,在列表中找到并勾选“Windows Media Player”组件,单击“确定”按钮。将该组件添加到指定的工具箱选项卡中 
然后在工具箱里面找 Windows Media Player 控件,拉到form里面,拉出来的控件就是AxWindowsMediaPlayer了,打开属性窗口,在点击拉过来的控件,可以清楚的看到控件名称为AxWindowsMediaPlayer1
------解决方案--------------------
使用WindowsMediaPlayer,
不过,这个东西要他支持的格式才可以,比如不支持的格式,播放不了,也就取不到时长的!
------解决方案--------------------
C# code
 

  ①   引用shell32底层接口c:windowssystem32shell32.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;
            }
        }

------解决方案--------------------
http://butlandblog.appspot.com/log-14.html

获取 FLV的