Skip to main content
November 30, 2010
Answered

How to get the NetConnection out of a flvplayback component in AS3?

  • November 30, 2010
  • 1 reply
  • 1693 views

http://www.flashcomguru.com/index.cfm/2009/8/14/flvplayback-obtain-nc-reference

I followed the above example in AS2,but only get the error:

Call to a possibly undefined method getNetConnection through a reference with static type fl.video:INCManager.


Here's my code:

             this.addEventListener(Event.ENTER_FRAME,
                                   function() {
                                       if ((nc = player.ncMgr.getNetConnection()) != undefined)
                                       {
                                           trace(nc);
                                       }
                                   });

Anyone knows how to do it in AS3?
    This topic has been closed for replies.
    Correct answer amit_kr

    You're still not using flvplayback component...


    Hi,

    Drag the flvplayback component on the stage and name it to "vidplayer" in properties panel. Then you can use the following sample code :

    import flash.utils.setInterval;
    import flash.utils.setTimeout;
    import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.events.*;

    import fl.video.FLVPlayback;
    import fl.video.VideoPlayer;
    import fl.video.VideoEvent;

    import flash.display.MovieClip;

    VideoPlayer.iNCManagerClass = fl.video.NCManagerNative;
    vidplayer.isLive = false;
    vidplayer.isDVR = false; 
    vidplayer.source = "rtmp://localhost/vod/sample";

    var videoplayer:VideoPlayer;
    var flvplayback:FLVPlayback;
    flvplayback = FLVPlayback(this.getChildByName("vidplayer"));
    videoplayer = flvplayback.getVideoPlayer(0);
    setTimeout(initMonitor,5000);

    function initMonitor():void
    {
    if (videoplayer.netStream!=null)
    {
      trace("Video is playing!!");
      if(videoplayer.netConnection)
      {
       trace("Got NetConnection!!");
      }
    }
    else
    {
      trace("Main.as : " + "Not connected to FMS yet - Trying again ....")
      setTimeout(initMonitor,5000);
    }     
    }

    Regards,

    Amit

    1 reply

    Participant
    December 1, 2010

    This has worked for me.

    package

    com.video

    {

    import flash.display.Sprite;

    import flash.events.*;

    import flash.media.Video;

    import flash.net.NetConnection;

    import flash.net.NetStream;

    public class FLVStream extends Sprite

    {

    public static const ERROR:String="vidError";

    private var videoURL:String = "";

    private var connection:NetConnection;

    private var stream:NetStream;

    private var vidW:Number;

    private var vidH:Number;

    public function FLVStream(arg_url:String,arg_w:Number,arg_h:Number)

    {

    videoURL = arg_url;

    vidW = arg_w;

    vidH = arg_h;

    connection =

    new NetConnection();

    connection.client=

    this;

    connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

    connection.connect(

    "rtmp://FEED GOES HERE/");

    }

    private function netStatusHandler(event:NetStatusEvent):void {

    switch (event.info.code) {

    case "NetConnection.Connect.Success":

    connectStream();

    trace ("success connecting");

    break;

    case "NetStream.Play.StreamNotFound":

    trace("Unable to locate video: " + videoURL);

    dispatchEvent (

    new Event(ERROR));

    break;

    }

    }

    private function connectStream():void {

    stream =

    new NetStream(connection);

    stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

    var client:Object = new Object();

    client.onMetaData = onMetaData;

    //client.onBWDone = onBWDone;

    stream.client = client;

    var video:Video = new Video(vidW,vidH);

    video.attachNetStream(stream);

    stream.play(videoURL);

    addChild(video);

    }

    private function securityErrorHandler(event:SecurityErrorEvent):void {

    trace("securityErrorHandler: " + event);

    }

    private function asyncErrorHandler(event:AsyncErrorEvent):void {

    // ignore AsyncErrorEvent events.

    }

    public function onBWDone():void{

    trace("onBWDone");

    }

    public function onFCSubscribe(info:Object):void{

    trace("worked");

    }

    public function onXMPData(infoObject:Object):void

    {

    //trace("onXMPData Fired\n");

    }

    public function onMetaData(infoObject:Object):void

    {

    //trace("FLVPlayer -> onMetaData");

    }

    }

    }

    December 1, 2010

    edgeboyTV6

    It seems you are not using flvplayback component,but write your own logic to play the stream...

    Participant
    December 1, 2010

    my bad... i think you just need this part

    connection = new NetConnection();

    connection.client=this;

    connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);

    connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);

    connection.connect("rtmp://FEED GOES HERE/");

    then you just need the corresponding functions from above... just drop the private from the coding, and substitute your file name for "videoURL"