在文件夹下有一个000.asf文件,把鼠标放上去会出现一个持续时间,这个持续时间就是播放时间,我要用c#程序获得这个播放时间,怎么做啊,,想了半天了,头大如斗啊!问了好几个论坛了,都没有人会,哪位大虾给我解决了,把分如数奉上啊!帮忙啊!小弟感激不尽啊!

解决方案 »

  1.   

    好象你说的那个持续时间不知道怎么获取!
    private void button4_Click(object sender, EventArgs e)
            {
               FileInfo file = new FileInfo(@"E:\e\新建文件夹\A1699654.mp3");
               string ss=file.Attributes.ToString(); //创建时间
                MessageBox.Show(ss);
            }
      

  2.   

    给你段代码参考下吧!使用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 TimeSpan(0, 0, 0, 0, (int)Convert.ToDouble(buf.ToString().Trim())); 
    textBox1.Text = ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds + "." + ts.Milliseconds;
      

  3.   

    用WindowsMediaPlayer控件
    参考:
    [currentMedia] 当前媒体属性 
    currentMedia.duration:double; 媒体总长度 
    currentMedia.durationString:string; 媒体总长度,字符串格式。如“03:24” 
    currentMedia.getItemInfo(const string); 获取当前媒体信息"Title"=媒体标题,"Author"=艺术家,"Copyright"=版权信息,"Description"=媒体内容描述,"Duration"=持续时间(秒),"FileSize"=文件大小,"FileType"=文件类型,"sourceURL"=原始地址 
    currentMedia.setItemInfo(const string); 通过属性名设置媒体信息 
    currentMedia.name:string; 同 currentMedia.getItemInfo("Title") 
      

  4.   

    Guyschaos:
    textBox1.Text = ts.ToString();就可以了
      

  5.   

     Guyschaos  的方法我试了,,可是老报错!
      

  6.   

    我这没错啊!是不是引用没加啊?
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;
    using System.Data.SqlClient;
    using System.IO;
    using System.Runtime.InteropServices;namespace listbox
    {
        public partial class Form1 : Form
        {
            public Form1()
            {
                InitializeComponent();
            }        [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);         private void button5_Click(object sender, EventArgs e)
            {
                StringBuilder shortpath = new StringBuilder(80);
                GetShortPathName(@"E:\e\新建文件夹\A1699654.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 TimeSpan(0, 0, 0, 0, (int)Convert.ToDouble(buf.ToString().Trim()));
                this.textBox1.Text = ts.Hours + ":" + ts.Minutes + ":" + ts.Seconds + "." + ts.Milliseconds;
            }
        }
    }
      

  7.   

    楼主结贴吧,Guyschaos 的方法ok.