Shell32.ShellClass服務器操做系統沒法獲取 音頻文件時長問題

前言:服務器

上傳音頻文件,自動寫入此音頻文件的時長,這裏用 COM組件Microsoft Shell Controls And Automation來實現。測試

 

首先spa

一、引用:Microsoft Shell Controls And Automation操作系統

注意:這裏是1.0版本的,有的使用的是1.2版本的,若是1.0的有問題,請換成1.2的3d

 

二、代碼以下code

                string strFileName = FileHelper.MapPath(linkUrl);//linkUrl是上傳到服務器的路徑
                string dirName = System.IO.Path.GetDirectoryName(strFileName);
                string SongName = System.IO.Path.GetFileName(strFileName);//得到名稱  
                FileInfo fInfo = new FileInfo(strFileName);
                Shell32.ShellClass sh = new Shell32.ShellClass();
                Shell32.Folder dir = sh.NameSpace(dirName);
                Shell32.FolderItem item = dir.ParseName(SongName);                
                string strTime = System.Text.RegularExpressions.Regex.Match(dir.GetDetailsOf(item, -1), "\\d:\\d{2}:\\d{2}").Value;  //時長 
                duration = Convert.ToInt64(TimeSpan.Parse(strTime).TotalSeconds); //音頻的時常,單位
                size = fInfo.Length;//字節數(這個是獲取文件大小,單位是Byte)

上面這段代碼在本地測試的時候是徹底可以讀到的blog

可是發佈在服務器上的時候,下面句代碼會報錯,緣由是GetDetailsOf(item, -1)方法獲取不到任何信息string

 string strTime = System.Text.RegularExpressions.Regex.Match(dir.GetDetailsOf(item, -1), "\\d:\\d{2}:\\d{2}").Value;  //時長

因而去服務器查看了文件的詳細信息,以下圖所示,並無時長信息。it

因此這個是由操做系統致使的GetDetailsOf(,)獲取不到音頻文件時長的問題。io

 

三、解決方法:

這個問題主要是服務器沒有安裝關於音頻的功能,添加上功能便可。

注意:安裝這兩個功能後服務器會被要求重啓才能生效

相關文章
相關標籤/搜索