How to load a ByteArray FLV in OSMF?

1.6k views Asked by At

I'm working on a local application ( it's not a website or nothing related ) and I have various FLVs with a very simple encryptation method by now (just like adding 10 at each byte).

I can load/play them using NetStream.appendBytes() after decrypting, but that happens only after I read all video data it's not streamed.

What I really need is to stream those videos from a remote url, and decrypting while receiving data, using a OSMF based player that I already have built. I'm lost on how OSMF deals with FLV, otherwise, I would try to create a plugin or something like. I'd be very thankful if someone point me how to deal with that.

But I'd be happy if someone help me to find a way to load a local file using OSMF, passing a ByteArray value, instead of a url (below). Or even giving me directions to create a OSMF plugin to solve my problem.

videoElement.resource = "video_url/video.flv";

This is my current code just to play my decoded FLV byte array

private function playBytes(bytes:ByteArray):void 
{
            // detecting it's header
            if (bytes.readUTFBytes(3) != "FLV")
            {
                _text.appendText("\nFile \""+ file +"\" is not a FLV")
                return void;
            }

            bytes.position = 0;
            netConnection.connect(null);
            netStream = new NetStream(netConnection);
            netStream.client = { onMetaData:function(obj:Object):void { } }
            video.attachNetStream(netStream);

            addChild(video); 


            // 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);
}
1

There are 1 answers

1
jc.021286 On BEST ANSWER

Interesting post, I'd be interested to see the answer. Looking at something similar myself, though not with a stream, I came across the following.

http://ntt.cc/2008/07/15/bitsreader-read-bits-from-given-bytearray.html

After passing the byte array you can use bits.read(8) of a 10 bit array. Perhaps this would send you down the correct path? Otherwise, I'm thinking you'd need to break it apart and essentially do smaller sections to buffer in order to concatenate all the buffered data...

Just a thought,