Reputation: 129
Is there any way of playing a byteArray through a FLVPlayback component?
I want to load an Encrypted video, decrypt it and play it. I can do the loading and decrypting part but i don't know how to play it through a FLVPlayback component. With seeking functions and play stop buttons.
Upvotes: 1
Views: 862
Reputation: 604
There is a way to load and play FLV video in ByteArray form, but I don't know if it's possible to couple this with the seek, play and pause functionality through an FLVPlayback component itself.
In my example I've added pause/unpause functionality, but seeking is difficult since the workaround treats this ByteArray as an RTMP stream from a server, as opposed to a progressively loaded video.
This is a document class for an FLA with an FLVPlayback component on the stage (with instance name flvPlayback
), and it just embeds a local FLV as ByteArray, which is referenced at the top:
package {
import flash.display.Sprite;
import flash.events.MouseEvent;
import flash.events.NetStatusEvent;
import flash.net.NetConnection;
import flash.net.NetStream;
import flash.net.NetStreamAppendBytesAction;
import flash.utils.ByteArray;
import fl.video.FLVPlayback;
public class VideoFromByteArray extends Sprite {
[Embed(source="your_video.flv", mimeType="application/octet-stream")]
private var TestVideo:Class;
public var flvPlayback:FLVPlayback; //Instantiated on stage in FLA//
private var _nc:NetConnection;
private var _ns:NetStream;
private var _ba:ByteArray;
public function VideoFromByteArray() {
ui_init();
}
private function ui_init():void {
_nc = new NetConnection();
_nc.connect(null);
_ns = new NetStream(_nc);
_ns.client = { };
_ns.addEventListener(NetStatusEvent.NET_STATUS, ns_netStatus);
flvPlayback.getVideoPlayer(0).attachNetStream(_ns);
_ba = new TestVideo();
_ns.play(null);
_ns.appendBytes(_ba);
_ns.send("|RtmpSampleAccess", true, true);
stage.addEventListener(MouseEvent.CLICK, stage_click);
}
private function stage_click(evt:MouseEvent):void {
_ns.togglePause();
}
private function ns_netStatus(event:NetStatusEvent):void {
var code:String = event.info.code;
switch(code) {
case "NetStream.Buffer.Empty":
_ns.seek(0);
break;
case "NetStream.Seek.Notify":
if (event.info.seekPoint == 0) ns_seekToBeginning();
break;
}
}
private function ns_seekToBeginning():void {
_ns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);
_ns.appendBytes(_ba);
_ns.appendBytesAction(NetStreamAppendBytesAction.END_SEQUENCE);
}
}
}
Upvotes: 2