Skip to main content
Participant
September 9, 2015
Question

play a flv video, and if the video is missing or when i have error play another one in another location

  • September 9, 2015
  • 1 reply
  • 397 views

hello,

First sorry for my english, i use to speak french, and i'm really new in flash so

here is my problem

i want to play a flv video locate in my hardisk

i'm using this

    var vid:Video;

    var nc:NetConnection = new NetConnection();

    nc.connect(null);

    var ns:NetStream = new NetStream(nc);

    ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

    var customClient:Object = new Object();

    customClient.onMetaData = metaDataHandler;

    ns.client = customClient;

    ns.play("../docs/video1.flv");

    

    vid = new Video();

    vid.attachNetStream(ns);

    addChild(vid);

    

    function asyncErrorHandler(event:AsyncErrorEvent):void

    {

    trace(event.text);

    }

    

    function metaDataHandler(infoObject:Object):void {

    vid.width = infoObject.width;

    vid.height = infoObject.height;

    }

it's working with no problem.

but i want to add a condition in case the video can be play for any reason ( video is missing, wrong name, wrong format, any error...)

in this case i want flash to play another video locate in a other place

i hope is clear enough, and i hope someone can help me with that

thank you

This topic has been closed for replies.

1 reply

kglad
Community Expert
Community Expert
September 10, 2015

use the netconnection netstatusevent. eg,

var vid: Video = new Video();

var ns: NetStream

var nc: NetConnection = new NetConnection();

var customClient:Object = this;

customClient.onMetaData = metaDataHandler;

nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);

nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorF);

nc.connect(null);

function netStatusF(e:NetStatusEvent):void {

switch (e.info.code) {

case "NetConnection.Connect.Success":

connectF();

break;

case "NetStream.Play.StreamNotFound":

// do whatever

break;

}

}

function connectF():void {

ns = new NetStream(nc);

ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);

ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

ns.addEventListener(IOErrorEvent.IO_ERROR, ioErrorF);

ns.client = customClient;

vid.attachNetStream(ns);

addChild(vid);

}

Participant
September 10, 2015

thank you very much for your reply

can you help me with one more thing

i don't really understand how to put it together, i still have this error when the video is missing

Error #2044: NetStatusEvent non pris en charge : level=error, code=NetStream.Play.StreamNotFound

  at EX_video_fla::MainTimeline/frame1()

is that possible  in case the video1 can't be play, than to play the video2 ?

here is where  the main video is located


ns.play("sync/bel/video/video1.flv");


and here the location of the video2 in case there is a error with video1


("sync/safe/video2.flv");




Thank you very much

kglad
Community Expert
Community Expert
September 10, 2015

var vid: Video = new Video();

var ns: NetStream

var nc: NetConnection = new NetConnection();

var customClient:Object = this;

customClient.onMetaData = metaDataHandler;

nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);

nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorF);

nc.connect(null);

function netStatusF(e:NetStatusEvent):void {

switch (e.info.code) {

case "NetConnection.Connect.Success":

connectF();

break;

case "NetStream.Play.StreamNotFound":

connectF('video2.flv');  // but i would probably loop through an array of possible videos.

break;

}

}

function connectF(videoS:String='video1.flv'):void {

ns = new NetStream(nc);

ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusF);

ns.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);

ns.addEventListener(IOErrorEvent.IO_ERROR, ioErrorF);

ns.client = customClient;

ns.play(videoS);

vid.attachNetStream(ns);

addChild(vid);

}