actionscript-3flashflvnetstream

play a external flv video


Hello please someone can help me with this ...

I want to play a external flv video ("../sync/video/video.flv"), but in case the video is missing or when there is a (StreamNotFound) error I want to play automatically another flv video.

case "NetStream.Play.StreamNotFound":
    ns.play("../sync/filler/video2.flv");

but it doesn't work ....

here is the full code :

var vid:Video;
var nc:NetConnection = new NetConnection();
    nc.connect(null);
var ns:NetStream = new NetStream(nc);

var customClient:Object = new Object();
    customClient.onMetaData = metaDataHandler;
ns.client = customClient;
ns.play("../sync/video/video.flv");

vid = new Video();
vid.attachNetStream(ns);
addChild(vid);

function netStatusF(e:NetStatusEvent):void
{
    switch (e.info.code)
    {
        case "NetStream.Play.StreamNotFound" :
            ns.play("../sync/filler/video2.flv");
            break;
    }
}

function metaDataHandler(infoObject:Object):void
{
    vid.width = infoObject.width;
    vid.height = infoObject.height;
}

Solution

  • You have just to add a NetStatusEvent.NET_STATUS event listener to your NetStream object :

    ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);
    

    Then you have to assure that your second video file exist, otherwise you'll have a looping problem.

    Hope that can help.