3

I have Adobe Media Server 5 (starter) up and running on Windows 7

I have a HelloWorld application on the server, and a client flash file that connects to it.

Now I want to modify this application to stream a video that I've placed on the server

To make that happen, I wrote some code, which I've pasted below. The important bits are under the netConnectionHandler function.

The NetStream I've posted now gives me a StreamNotFound error

The path to my video is

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

The nc.connect server path is rtmp://localhost/HelloWorld

I'm following these official instructions to do this, but I can't get this to work.

When do the ns.play as below, I get a SteamNotFound error. However, if I were to enter ns.play("sample") I get:

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; 
            } 
        }
    }


}

Console output:

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
  • have you tried using the build in VOD application? drop your media file in there. – BadFeelingAboutThis Jul 04 '13 at 00:20
  • Is that the only possible way to stream videos from the server? The goal is to make my own application –  Jul 05 '13 at 16:03
  • It's not the only way, but you can use it as a starting point and modify it however you'd like. Your problem is likely using the 'media' path in your connection. your application code/settings tell it where to look for media, not your connection. Your connection should be: `rtmp://localhost/helloworld/sample` – BadFeelingAboutThis Jul 05 '13 at 16:16
  • You either have to change the `storageDir` param in the application's xml file, or rename your media file to `streams` (the default place it will look) – BadFeelingAboutThis Jul 05 '13 at 16:19
  • @LDMediaServices the `rtmp://localhost/helloworld/sample` path returns the same `StreamNotFound` error. `sample`, however returns the `Play.Start` event. However, I see no video or audio –  Jul 05 '13 at 16:29
  • @LDMediaServices my App doesn't have an xml file. Should it? –  Jul 05 '13 at 16:29
  • it's optional. You only need it if you need to customize things beyond the default. (like which directories to look for media files) – BadFeelingAboutThis Jul 05 '13 at 16:31

1 Answers1

1

Your issue is likely the format of your url.

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

This tells Adobe Media Server to load an instance of the HelloWorld application named media In Adobe media server, you don't pass in any paths for media when connecting. It looks in the streams folder for the media passed. You can also use the Application.xml file (or the main config file) to add other directories to look in for the media.

The easiest way to make this work, is to rename your media folder to "streams". Then connect like so:

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

Leaving off the .flv should also work just fine. You may need to make a sub-folder in the streams folder called _definst_ and put your media inside of that.

If it still doesn't work, you likely have an issue with your Application.xml.


Try creating an Application.xml file in your application directory. Use the following:

<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>
BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
  • I still get `StreamNotFound` errors when changing the folder, using the new path, and even with the `_definst_` folder. I don't have any sort of **Application.xml** file. –  Jul 05 '13 at 16:33
  • I edited my question to include some new information right before the "code break" –  Jul 05 '13 at 16:39
  • Okay, something worked, and I can get video playing. Once I found out exactly what happened, I'll give you a check mark. –  Jul 05 '13 at 17:50
  • I copied my `HelloWorld` project and removed all the duplicate videos and unnecessary folders. In the end I ended up with two applications with the exact same file structure and no `Application.xml` file. If I `NetConnect` to my copy, it works, but my original doesn't, even though all the files are in equivalent places –  Jul 05 '13 at 18:54
  • But the `_definst_`folder was the key, and I also had to get rid of the `error 1069` –  Jul 05 '13 at 18:54