【问题标题】:Playing a video on local Adobe Media Server在本地 Adob​​e Media Server 上播放视频
【发布时间】:2013-07-01 19:21:46
【问题描述】:

我已在 Windows 7 上启动并运行 Adob​​e Media Server 5(入门版)

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

现在我想修改此应用程序以流式传输我放置在服务器上的视频

为了实现这一点,我编写了一些代码,并将其粘贴在下面。 重要的位在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

【问题讨论】:

  • 您是否尝试过使用内置 VOD 应用程序?将您的媒体文件放在那里。
  • 这是从服务器流式传输视频的唯一可能方式吗?目标是制作我自己的应用程序
  • 这不是唯一的方法,但您可以将其作为起点并根据需要进行修改。您的问题可能是在您的连接中使用了“媒体”路径。您的应用程序代码/设置告诉它在哪里寻找媒体,而不是您的连接。您的连接应该是:rtmp://localhost/helloworld/sample
  • 您要么必须更改应用程序 xml 文件中的 storageDir 参数,要么将您的媒体文件重命名为 streams(默认位置)
  • @LDMediaServices rtmp://localhost/helloworld/sample 路径返回相同的 StreamNotFound 错误。 sample,但返回 Play.Start 事件。但是,我看不到任何视频或音频

标签: actionscript-3 flash netstream adobe-media-server


【解决方案1】:

您的问题可能是您的网址格式。

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

这告诉 Adob​​e Media Server 加载名为 media 的 HelloWorld 应用程序实例 在 Adob​​e 媒体服务器中,您在连接时不会传递任何媒体路径。它在流文件夹中查找传递的媒体。您还可以使用 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>

【讨论】:

  • 在更改文件夹、使用新路径甚至使用 _definst_ 文件夹时,我仍然收到 StreamNotFound 错误。我没有任何类型的 Application.xml 文件。
  • 我编辑了我的问题,在“代码中断”之前添加了一些新信息
  • 好的,有些工作,我可以播放视频了。一旦我确切地知道发生了什么,我会给你一个复选标记。
  • 我复制了我的HelloWorld 项目并删除了所有重复的视频和不必要的文件夹。最后,我得到了两个文件结构完全相同但没有Application.xml 文件的应用程序。如果我 NetConnect 复制到我的副本,它可以工作,但我的原始文件没有,即使所有文件都在相同的位置
  • 但是_definst_文件夹是关键,我还必须摆脱error 1069
猜你喜欢
  • 2010-10-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-10
  • 1970-01-01
  • 2021-10-27
  • 1970-01-01
  • 2017-03-07
  • 2011-06-17
相关资源
最近更新 更多