利用live555 Media Server和VLC Active ocx實現簡單的流媒體點播系統(B/S)

http://blog.csdn.net/xy365/article/details/8230670

1. 大體的架構及流程

        實現視頻點播系統,B/S架構,服務端至少應該是兩個服務器:流媒體服務器,web服務器。客戶端則就是web頁面。當開啓頁面後則是客戶端和服務器的第一次交互,通過http協議得到頁面。裏面會有流媒體地址的信息,瀏覽器裏面點擊顯示視頻組件,將流媒體的地址傳給流媒體播放器,並啓動播放器去請求視頻。這是第二次交互。服務器端流媒體服務器發送流給客戶端,頁面上播放就okay了。
 
        2. 環境及所需軟件
        測試環境是xp sp2及IE 6瀏覽器。
        服務端(IP地址:10.25.67.22):
        流媒體服務器先用個簡單的:live555 Media Server(http://www.live555.com/mediaServer/windows/live555MediaServer.exe)
        Web服務器可以用Tomcat,IIS或者其他的Web服務器都可以。本文直接使用靜態頁面進行測試,不搭建Web服務。
        客戶端(IP地址:10.25.67.100):vlc-2.0.4的Activex ocx
        
        3. 配置流媒體服務器
        下載完live555 Media Server之後放到服務端D:/video目錄(需要保證在video目錄下有01.ts、02.mp3文件)下面,啓動時會有以下信息:
"Play streams from this server using the URL
        rtsp://172.16.128.8/<filename>
where <filename> is a file present in the current directory."
並且後面還會有live555支持的視頻格式。本測試就用的mp3和ts格式。其他格式沒有試驗過。
        mp3好說,ts怎麼得到呢?這時候vlc就出場了。vlc有轉換保存功能,媒體->轉換/保存->選擇某個文件後點擊轉換/保存->流輸出頁面勾選本地播放,勾選文件並且瀏覽得到個文件名,注意後綴爲ts而不是ps,方案封裝選MPEG-TS,然後點擊save。把你選擇的視頻播放一遍之後,ts格式的文件就生成好了。
        將生成好的ts文件和網上下載的mp3放到d:/video下面,本測試爲01.ts及02.mp3。這樣流媒體服務器就配置好了。
 
        4. 客戶端web頁面測試
        本web頁面代碼是vlc的Activex測試代碼test.html上修改精簡的。
       
[html] view plaincopy
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   
  2. <html xmlns="http://www.w3.org/1999/xhtml" >   
  3. <head>   
  4. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />   
  5. <script>   
  6. var itemId = 0;   
  7. function getVLC(name)   
  8. {   
  9.         if (window.document[name])      
  10.         {   
  11.                 return window.document[name];   
  12.         }   
  13.         if (navigator.appName.indexOf("Microsoft Internet")==-1)   
  14.         {   
  15.                 if (document.embeds && document.embeds[name])   
  16.                         return document.embeds[name];      
  17.         }   
  18.         else   
  19.         {   
  20.                 return document.getElementById(name);   
  21.         }   
  22. }   
  23.   
  24. function doGo(mrl)   
  25. {   
  26.         var vlc = getVLC("vlc");   
  27.         itemId=vlc.playlist.add(mrl);   
  28.         vlc.playlist.playItem(itemId);   
  29.         document.getElementById("btn_stop").disabled = false;   
  30. }   
  31.   
  32. function updateVolume(deltaVol)   
  33. {   
  34.         var vlc = getVLC("vlc");   
  35.         vlc.audio.volume += deltaVol;   
  36. }   
  37.   
  38. function doPlay()   
  39. {   
  40.         vlc.playlist.playItem(itemId);   
  41.            
  42.         document.getElementById("btn_stop").disabled = false;   
  43.         document.getElementById("btn_play").disabled = true;   
  44. }   
  45.   
  46. function doStop()   
  47. {   
  48.         getVLC("vlc").playlist.stop();   
  49.         document.getElementById("btn_stop").disabled = true;   
  50.         document.getElementById("btn_play").disabled = false;   
  51. }   
  52. </script>   
  53. </head>   
  54. <body>   
  55. <div style="margin: 50px">   
  56.         <a title="rtsp://10.25.67.22/01.ts" href="#" onclick="doGo(this.title);return false;">01.ts</a>   
  57.         <span style="margin: 20px;" />   
  58.         <a title="rtsp://10.25.67.22/02.mp3" href="#" onclick="doGo(this.title);return false;">02.mp3</a>   
  59.         <span style="margin: 20px;" />   
  60. </div>   
  61. <div>   
  62.         <object classid="clsid:9be31822-fdad-461b-ad51-be1d1c159921"   
  63.                 width="640"   
  64.                 height="480"   
  65.                 id="vlc"   
  66.                 events="true">   
  67.         <param name="mrl" value="" />   
  68.         <param name="showdisplay" value="true" />   
  69.         <param name="autoloop" value="false" />   
  70.         <param name="autoplay" value="false" />   
  71.         <param name="volume" value="50" />   
  72.         <param name="starttime" value="0" />   
  73.         <embed pluginspage="http://www.videolan.org"   
  74.                      type="application/x-vlc-plugin"   
  75.                      version="videolan.vlcplugin.2"   
  76.                      width="640"   
  77.                      height="480"   
  78.                      name="vlc">   
  79.         </embed>   
  80.         </object>   
  81. </div>   
  82. <div>   
  83. <input type=button id="btn_play" value=" 播放 " onClick='doPlay();' disabled="true">   
  84. <input type=button id="btn_stop" value="停止" onClick='doStop();' disabled="true">   
  85. <input type=button value="靜音切換" onclick='getVLC("vlc").audio.togglemute();'>   
  86. <input type=button value="減小音量" onclick='updateVolume(-10)'>   
  87. <input type=button value="增加音量" onclick='updateVolume(+10)'>   
  88. </div>   
  89. </body>   
  90. </html>  
   保存爲VLCTest.html,以IE瀏覽器打開即可。
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章