2013-07-03 41 views
3

上的視頻我有Adobe媒體服務器5(首發)並在Windows 7播放本地的Adobe Media服務器

運行我的服務器上的應用程序HelloWorld,以及與其相連的客戶端Flash文件。

現在我想修改這個應用程序流,我已經放在服務器

。要做到這一點的視頻,我寫了一些代碼,我已經粘貼下面。 重要的位在netConnectionHandler函數下。

我現在已經發布的NetStream給了我一個StreamNotFound錯誤

我的視頻路徑是

C:\Program Files\Adobe\Adobe Media Server 5\applications\HelloWorld\sample.mp4

nc.connect服務器路徑爲rtmp://localhost/HelloWorld

我下面these official instructions做到這一點,但我無法得到這個工作。

如何做ns.play如下,我得到一個SteamNotFound錯誤。但是,如果我進入ns.play("sample")我得到:

ns event.info.code: NetStream.Play.Start 
ReferenceError: Error #1069: Property onMetaData not found on flash.net.NetStream and there is no default value. 

package { 
    import flash.display.MovieClip; 
    import flash.net.Responder; 
    import flash.net.NetConnection; 
    import flash.events.NetStatusEvent; 
    import flash.events.MouseEvent; 
    import flash.net.URLRequest; 
    import flash.net.URLLoader; 
    import flash.events.Event; 
    import flash.net.NetStream; 
    import flash.media.Video; 


    public class HelloWorld extends MovieClip { 
     private var nc:NetConnection; 
     private var myResponder:Responder = new Responder(onReply); 
     private var server:String; 



     public function HelloWorld(){ 
      textLbl.text = ""; 
      connectBtn.label = "Connect"; 
      connectBtn.addEventListener(MouseEvent.CLICK, connectHandler); 
     } 

     public function connectHandler(event:MouseEvent):void{ 
      if(connectBtn.label=="Connect") { 
       var myLoader:URLLoader = new URLLoader(); 
       myLoader.load(new URLRequest("config.xml")); 
       myLoader.addEventListener(Event.COMPLETE, function(e:Event):void{ 
       var serviceXML = new XML(e.target.data);      
       trace("Connecting..."); 
       nc = new NetConnection(); 
       nc.addEventListener(NetStatusEvent.NET_STATUS,netConnectionHandler); 
       //Connect to the server 
       nc.connect(serviceXML.ServerPath.text());//Which is "rtmp://localhost/HelloWorld" 

       //Call the server's client function 'serverHelloMsg' in HellowWorld.asc 
       nc.call("serverHelloMsg",myResponder,"World"); 
       connectBtn.label="Disconnect"; 
       }); 

      }else{ 
       trace("Disconnecting..."); 
       //Close the connection. 
       nc.close(); 
       connectBtn.label = "Connect"; 
       textLbl.text = ""; 
      } 
     } 

     private function onReply(result:Object):void{ 
      trace("onReply recieved value: " + result); 
      textLbl.text = String(result); 
     } 

     private function showXML(e:Event):void{ 
      XML.ignoreWhitespace=true; 
      var config:XML = new XML(e.target.data); 
      trace(config.serverpath.text()); 
      server = config.serverpath.text(); 

     } 
     public function netStatusHandler(event:NetStatusEvent):void { 
      trace("ns connected is: " + nc.connected); 
      trace("ns event.info.level: " + event.info.level); 
      trace("ns event.info.code: " + event.info.code); 
     } 

     public function netConnectionHandler(event:NetStatusEvent):void { 
      trace("connected is: " + nc.connected); 
      trace("event.info.level: " + event.info.level); 
      trace("event.info.code: " + event.info.code); 
      switch (event.info.code) 
      { 
       case "NetConnection.Connect.Success": 
        var v:Video = new Video(); 
        v.width=200; 
        v.height=200; 
        v.x=0; 
        v.y=0; 
        v.visible=true; 
        v.opaqueBackground=false; 
        stage.addChild(v); 

        var ns:NetStream = new NetStream(nc); 
        ns.addEventListener(NetStatusEvent.NET_STATUS,netStatusHandler); 
        v.attachNetStream(ns); 
        ns.play("rtmp://localhost/HelloWorld/sample.flv"); 

        break; 
       case "NetConnection.Connect.Rejected": 
        trace ("Oops! the connection was rejected"); 
        // try to connect again 
        break; 
       case "NetConnection.Connect.Failed": 
        trace("The server may be down or unreachable"); 
        // display a message for the user 
        break; 
       case "NetConnection.Connect.Closed": 
        trace("The connection was closed successfully - goodbye"); 
        // display a reconnect button 
        break; 
      } 
     } 
    } 


} 

控制檯輸出:

Connecting... 
connected is: true 
event.info.level: status 
event.info.code: NetConnection.Connect.Success 
onReply recieved value: Hello, World! 
ns connected is: true 
ns event.info.level: error 
ns event.info.code: NetStream.Play.StreamNotFound 
ns connected is: true 
ns event.info.level: status 
ns event.info.code: NetStream.Play.Stop 
+0

您是否嘗試過在VOD應用程序中使用構建?把你的媒體文件放在那裏。 – BadFeelingAboutThis

+0

這是從服務器流式傳輸視頻的唯一可能方式嗎?目標是製作我自己的應用程序 – Houseman

+0

這不是唯一的方法,但您可以將其用作起點並根據需要對其進行修改。您的問題可能是在您的連接中使用「媒體」路徑。您的應用程序代碼/設置會告訴它在哪裏查找媒體,而不是您的連接。您的連接應該是:'rtmp:// localhost/helloworld/sample' – BadFeelingAboutThis

回答

1

您的問題可能是您的網址的格式。

ns.play("rtmp://localhost/HelloWorld/media/sample.flv"); 

這告訴的Adobe Media服務器加載一個名爲media 在Adobe媒體服務器HelloWorld應用程序的一個實例,你沒有任何路徑連接時傳遞媒體。它在傳遞媒體的流文件夾中查找。您也可以使用Application.xml文件(或主配置文件)來添加其他目錄以查找介質。

使這項工作最簡單的方法是將媒體文件夾重命名爲「流」。然後像這樣連接:

ns.play("rtmp://localhost/HelloWorld/sample.flv"); 

離開.flv也應該工作得很好。您可能需要在名爲_definst_的流文件夾中創建一個子文件夾,並將其放入該文件夾中。

如果它仍然不起作用,您可能會遇到與您的Application.xml有關的問題。


嘗試在應用程序目錄中創建Application.xml文件。使用以下內容:

<Application> 
    <StreamManager> 
     <VirtualDirectory> 
      <!-- Specifies application specific virtual directory mapping for recorded 
      streams. --> 
      <Streams>/;C:\Program Files\Adobe\Adobe Media Server 5\applications\HelloWorld\</Streams> 
     </VirtualDirectory> 
    </StreamManager> 
</Application> 
+0

當更改文件夾,使用新路徑,甚至使用_definst_'文件夾時,仍然會出現'StreamNotFound'錯誤。我沒有任何** Application.xml **文件。 – Houseman

+0

我編輯了我的問題,在「代碼中斷」之前添加了一些新的信息 – Houseman

+0

更新了我的答案以及如何創建application.xml文件 – BadFeelingAboutThis