用axWindowsMediaPLayer的确可以获得当前音乐的播放长度,但我想把很多歌曲的长度记录在listbox里面,每首歌都要放进去axplayer里面一次?太麻烦了吧?音乐的文件头有没有记录歌曲的播放长度的?比如MP3和WMA

解决方案 »

  1.   


    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;  
      

  2.   

    见鬼,再来~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;  
      

  3.   

    this.axWmp.currentMedia.durationString;
      

  4.   

    谢谢了,不过API对我来说很陌生,有没有普通点的方法呢?
      

  5.   

      study study studyup up up
      

  6.   


    建议你不要学C#,去学C++吧,可能可以不用API。