I have some FLV video files to be reproduced sequentially by a Flash video player. Suppose v1.flv and v2.flv. I want the player to start playing v2.flv once v1.flv has reached the end. According to this forum, the onPlayStatus
does not fire in progressive FLVs. What can be done? A snippet of what I am trying below:
public class MyClass extends Sprite {
private var nc : NetConnection;
private var ns : NetStream;
private var vid : Video;
private var vidURL : String = "v1.flv";
public function MyClass() {
var nsClient:Object = {};
nsClient.onPlayStatus = client_onPlayStatus;
nc = new NetConnection();
nc.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
nc.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
nc.connect(null);
ns = new NetStream(nc);
ns.play(vidURL);
ns.client = nsClient;
vid = new Video();
vid.attachNetStream(ns);
addChild(vid);
}
private function netStatusHandler(event : NetStatusEvent) : void {
trace(event.info.code);
switch(event.info.code) {
case "NetConnection.Connect.Success":
trace("Loaded stream: " + vidURL);
break;
case "NetStream.Play.StreamNotFound":
trace("Stream not found: " + vidURL);
break;
default:
}
}
private function client_onPlayStatus(event:Object) : void {
trace("status=" + event.info.code);
}
}
The only text that shows up in the trace output is:
NetConnection.Connect.Success
Loaded stream: /path/to/v1.flv
Any help will be appreciated!
I ended using part of charlie-boy's suggestion adapting MediaStream.as
to check every 100ms if the time
property of the NetStream
is the same (it's stuck in the end... or maybe just stuck but my specific situation will make that unlikely).
I added three properties to MediaStream
:
private var last_time:Number = -1;
private var last_check:int = 0;
private const check_delay:int = 100;
and changed the compareTime
function like this:
private function compareTime():void
{
if (isNaN(duration))
{
// when there is no metadata duration
if (getTimer() - last_check > check_delay)
{
// enough time has passed since last check
if (last_time==this.time)
{
timer.stop();
timer.removeEventListener(TimerEvent.TIMER, onTimer);
dispatchEvent(new StreamEvent(StreamEvent.COMPLETE, null));
}
else
{
last_check = getTimer();
last_time = this.time;
}
}
}
else if(!isNaN(duration) && this.time >= duration)
{
timer.removeEventListener(TimerEvent.TIMER, onTimer);
dispatchEvent(new StreamEvent(StreamEvent.COMPLETE, null));
}
}
The worst case scenario is a 100ms "stuck frame" before loading the next clip. Not so bad for my specific need.
Thanks all for the input.