WMV內建的ScripCommand, WMPlayer, Expression Encoder SDK

很久以前看rm檔案的時候會自己跳出網頁,我覺得滿神奇的,現在知道原來 wmv檔案也有了,只是他的term是 ScriptCommand。

ScriptCommand包含三個東西

string Type;

string Command:

TimeSpan Time;

比較奇怪的是,我使用WMPlayer元件無法取得wmv檔案的所有ScriptCommand。

例如:

   1:  for (int i = 1; i <= this.WMPlayer.currentMedia.markerCount; i++)
   2:  {
   3:        int MarkerTime = (int)this.WMPlayer.currentMedia.getMarkerTime(i);
   4:        string MarkerName = this.WMPlayer.currentMedia.getMarkerName(i).ToString();
   5:  }



這樣我就可以取得所有的Marker標記,但對於ScriptCommand卻無法取得,反而是WMPlayer提供一個事件


WMPlayer.ScriptCommand


   1:  void WMPlayer_ScriptCommand(object sender, AxWMPLib._WMPOCXEvents_ScriptCommandEvent e)
   2:  {
   3:        if (e.scType == "caption")
   4:           MessageBox.Show(e.param, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Information);
   5:  }



然後我們可以從 string e.param 取得 Command,然後 string e.scType 取得Type,注意他的型別都是string,所以彈性是很大的,你可以用Type=”caption”來代表要放一個字幕上去,用Type=”url”來代表要開啟一個URL。這樣在silverlight播放器就可以有很多應用~


但我們還是需要列舉所有的ScriptCommand啊,所以只能用Expression Encoder SDK來做了。


   1:  MediaItem mi = new MediaItem(WmvPath);
   2:  foreach (ScriptCommand sc in mi.ScriptCommands);



比較奇怪的是第一次呼叫 MediaItem 的時候都會超久的,大概需要10秒,應該是要載入Encoder SDK,但第二次之後只要十秒。
這樣會讓我的UI Hang住,所以我就在Form_Load使用

ThreadPool.QueueUserWorkItem(o => { new Microsoft.Expression.Encoder.Job(); });





這樣就可以避免第一次太久的情況囉~


 


查了資料發現http://msdn.microsoft.com/en-us/library/dd564081(VS.85).aspx,原來Windows Media Player 7 就已經支援 ScriptCommand了~

留言

這個網誌中的熱門文章

好貴的東元冷氣維修--馬達啟動電容

台大醫院 婁培人 耳鼻喉科 就診

機車無法充電之整流器壞掉--$650