as3 rtmp video stream on localhost red5 path issue
Asked Answered
S

1

2

Below is a basic code bit in as3 flash.A simple video streaming example using rtmp red5. But i seem to be having issues connecting to the stream.I am using the same video files as given with the red5 server demo installation.( i have verified the installed demo of ofla by running it properly) my output trace traces out as a connection success and the play start of the video file. But i am unable to get its metadata or get it actually playing.

netStatusHandler NetConnection.Connect.Success

netStatusHandler NetStream.Play.Reset

netStatusHandler NetStream.Play.Start

what am i missing here in regards to giving the path to the video file ? they are located in the same demo example folder which come with the default red5 installation.

package 
{
    import flash.display.*;
    import flash.events.*;
    import flash.media.*;
    import flash.net.*



    public class NetConnectionExample extends MovieClip
    {
        private var videoURL:String = "rtmp://localhost/oflaDemo/streams";
        private var connection:NetConnection;
        private var stream:NetStream;
        public function NetConnectionExample()
        {
            // constructor code
            connection = new NetConnection();
            connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
            connection.connect(videoURL, true);
        }
        private function netStatusHandler(event:NetStatusEvent):void
        {
            trace("netStatusHandler",event.info.code);
            switch (event.info.code)
            {
                case "NetConnection.Connect.Success":
                    connectStream();
                    break;
                case "NetStream.Play.StreamNotFound":
                    trace("Stream not found: " + videoURL);
                    break;
                case "NetStream.Play.Start":
                break;
            }
        }

        private function securityErrorHandler(event:SecurityErrorEvent):void
        {
            trace("securityErrorHandler: " + event);
        }

        private function connectStream():void
        {
            stream = new NetStream(this.connection);
            stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
            stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler)
            stream.client = new CustomClient();
            var video:Video = new Video();
            video.attachNetStream(stream);
            stream.play(videoURL+"avatar.flv");
            addChild(video);
        }
        function asyncErrorHandler(event:AsyncErrorEvent):void {
            // ignore AsyncErrorEvent events.
        }

    }
}

class CustomClient {
public function onMetaData(info:Object):void
{
    trace("metadata: duration=" + info.duration + " width=" + info.width + " height=" + info.height + " framerate=" + info.framerate);
}
public function onCuePoint(info:Object):void
{
    trace("cuepoint: time=" + info.time + " name=" + info.name + " type=" + info.type);
}
}

Edit: Related Where do I place a FLV file to stream on a local Red5 server?

Samons answered 23/1, 2012 at 12:1 Comment(2)
Sounds to me like a poorly encoded FLV Make sure the meta data is in the headerGulosity
the video does have its meta properly added. i figured out that this was a path issue.Samons
S
2

It was a path issue. the rtmp video folder of the application called oflaDemo is named streams. giving the path like so

 private var videoURL:String = "rtmp://localhost/oflaDemo";

and directly the file name after connecting the stream. works

 stream.play("avatar.flv");
Samons answered 24/1, 2012 at 10:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.