使用ffmpeg.exe獲取文件屬性信息,C#中可以在進程外異步調用這個工具,如下:
using (System.Diagnostics.Process pro = new System.Diagnostics.Process()) { pro.StartInfo.UseShellExecute = false; pro.StartInfo.ErrorDialog = false; pro.StartInfo.CreateNoWindow = true; pro.StartInfo.RedirectStandardError = true; pro.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe"; pro.StartInfo.Arguments = " -i " + fileName; pro.Start(); System.IO.StreamReader errorreader = pro.StandardError; pro.WaitForExit(1000); string result = errorreader.ReadToEnd(); if (!string.IsNullOrEmpty(result)) { result = result.Substring(result.IndexOf("Duration: ") + ("Duration: ").Length, ("00:00:00").Length); duration = result; } }
關於運行程序隱藏窗口的問題:
1、首先CreateNoWindow只對那些命令行程序有效。如果:cmd.exe。 (NoWindow理解成非消息循環程序可能更恰當)
2、如果要將CreateNoWindow設為true,那UseShellExecute必須為:false才有效。
3、想要使WindowStyle有效,UseShellExecute必須為:true。WindowStyle只對有UI界面的程序有效。(UseShellExecue默認為:true)
4、上述結論不是對所有程序有效,比如:calc.exe(你怎么就選中它來測試呢...),把calc.exe換成notepad.exe或Iexplore.exe或自己寫個WinForm程序什么的就可以看到效果了。
5、瞎猜的。 UseShellExecute為true時可能是調用了WndMain,而那些不聽話的程序都是因為沒對第四個參數:ShowCmd做處理?
6、對於計算器這類不聽話的家伙,好象只能System.Threading.Thread.Sleep(xxx)后ShowWindow了。但延遲多少時間是個問題,少了沒用,多了界面會彈出來一會才隱藏。