How to loop video using NetStream in Data Generation Mode
- by WesleyJohnson
I'm using a NetStream in Data Generation Mode to play an embeded FLV using appendBytes. When the stream is finished playing, I'd like to loop the FLV file. I'm not sure how to achieve this. Here is what I have so far (this isn't a complete example):
public function createBorderAnimation():void
{
// Load the skin image
borderAnimation = Assets.BorderAnimation;
// Convert the animation to a byte array
borderAnimationBytes = new borderAnimation();
// Initialize the net connection
border_nc = new NetConnection();
border_nc.connect( null );
// Initialize the net stream
border_ns = new NetStream( border_nc );
border_ns.client = { onMetaData:function( obj:Object ):void{ trace(obj); } }
border_ns.addEventListener( NetStatusEvent.NET_STATUS, border_netStatusHandler );
border_ns.play( null );
border_ns.appendBytes( borderAnimationBytes );
// Initialize the animation
border_vd = new Video( 1024, 768 );
border_vd.attachNetStream( border_ns );
// Add the animation to the stage
ui = new UIComponent();
ui.addChild( DisplayObject( border_vd ) );
grpBackground.addElement( ui );
}
protected function border_netStatusHandler( event:NetStatusEvent ):void
{
if( event.info.code == "NetStream.Buffer.Flush" || event.info.code == "NetStream.Buffer.Empty" )
{
border_ns.appendBytesAction( NetStreamAppendBytesAction.RESET_BEGIN );
border_ns.appendBytes( borderAnimationBytes );
border_ns.appendBytesAction( NetStreamAppendBytesAction.END_SEQUENCE );
}
}
This will loop the animation, but it starts chewing up memory like crazy. I've tried using NetStream.seek(0) and NetStream.appendBytesAction( NetStreamAppendBytesAction.RESET_SEEK ), but then I'm not sure what to do next. If you just try to call appendBytes again after that, it doesn't work, presumably because I'm appending the full byte array which has the FLV header and stuff? I'm not very familiar with how that all works.
Any help is greatly appreciated.