在本地Adobe Media Server上播放视频



我安装了Adobe Media Server 5(入门版)并在Windows 7 上运行

我在服务器上有一个HelloWorld应用程序,还有一个连接到它的客户端闪存文件

现在我想修改这个应用程序来流式传输我放在服务器上的视频

为了实现这一点,我写了一些代码,并粘贴在下面。重要位在netConnectionHandler函数下。

我发布的NetStream现在给了我一个StreamNotFound错误

我的视频路径是

C:Program FilesAdobeAdobe Media Server 5applicationsHelloWorldsample.mp4

nc.connect服务器路径为rtmp://localhost/HelloWorld

我按照这些官方指示来做这件事,但我无法让它发挥作用。

当按照下面的方式执行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

您的问题可能是url的格式。

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

此命令告诉Adobe Media Server加载名为media的HelloWorld应用程序实例在Adobe媒体服务器中,连接时不会传入任何媒体路径。它在流文件夹中查找传递的媒体。您还可以使用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 FilesAdobeAdobe Media Server 5applicationsHelloWorld</Streams> 
        </VirtualDirectory> 
    </StreamManager> 
</Application>

相关内容

  • 没有找到相关文章

最新更新