There are moments like this, when you read the documentation of the Flash Player and you discover and nice new API that you have been waiting for such a long time. Do you see what I mean ? Yes, you read it right, ByteArray access to NetStream class is coming and it works beautifully in Flash Player 10.1. As many of you, I was also waiting for this API when working on my FLV editing library and this day has come.

The API is called appendBytes on the NetStream class used in conjunction with the NetStreamAppendBytesAction class. It allows you to inject a ByteArray to the NetStream object and play the video. This API was designed originally for HTTP streaming, allowing forward seeking into HTTP delivered-video, but if you just load a ByteArray locally  through the FileReference API, voilà, you got local preview of video files without server round trip. If you read the documentation you'll notice that the API only works for now with FLV header-based files, but all codecs are supported (Sorenson, H.264, On2 VP6 and even AAC audio).

Here is a little demo which illustrates the API in the Flash Player 10.1 (make sure you are using the Flash Player 10.1 RC4 available on labs.adobe.com) :

A Flash animation should have appeared here, but it seems that your browser has an older version of the Flash Player or it is not installed at all. Please, install the last release of the Flash Player now, then reload this page.

The API is really simple :

// retrieve the FLV stream
var bytes:ByteArray = event.currentTarget.data;
// put the NetStream class into Data Generation mode 
netstream.play(null); 
// before appending new bytes, reset the position to the beginning 
netstream.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
// append the FLV video bytes
netstream.appendBytes(bytes);

This will allow new kind of apps and remove one more limitation that we had in the past ;)