Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to embed flv in flash and play it with AS3?

I want to create an ipad application with several videos. All videos must be embedded within flash, so no streaming. I can embed flv on timeline on play it that way, but is there some other way how I can control playback with Actionscript referencing video object that is in library or maybe using embed tags in AS - that way I would be able to gain more control and access cuepoints too.

like image 278
bukowski Avatar asked Jan 16 '23 16:01

bukowski


1 Answers

You have to embed file and append NetStream bytes :

[Embed(source = "movie.flv", mimeType = "application/octet-stream")]
public var bytes:Class;

public var video:Video = new Video(640, 480);

public function Main():void {

    addChild(video);

    var nc:NetConnection = new NetConnection();
    nc.addEventListener(NetStatusEvent.NET_STATUS , onConnect);
    nc.addEventListener(AsyncErrorEvent.ASYNC_ERROR , trace);


    var metaSniffer:Object=new Object();  
    nc.client=metaSniffer;
    metaSniffer.onMetaData=getMeta;
    nc.connect(null);
}

private function getMeta (mdata:Object):void {
    video.width=mdata.width/2;
    video.height=mdata.height/2;
};

private function onConnect(e:NetStatusEvent):void {
    if (e.info.code == 'NetConnection.Connect.Success') {
        trace(e.target as NetConnection);
        var ns:NetStream = new NetStream(e.target as NetConnection);

        ns.client = {};
        var file:ByteArray = new bytes();
        ns.play(null);

        ns.appendBytes(file);
        video.attachNetStream(ns);
    }

}
like image 63
turbosqel Avatar answered Jan 19 '23 06:01

turbosqel