Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flash / ActionScript 3: Load .FLV file into a MovieClip and start playing that FLV file

How can I load a FLV file into a MovieClip (lets call the instance "flvPlaceHolder") and start playing that FLV file.. using ActionScript 3?

like image 769
cllpse Avatar asked Jun 28 '09 21:06

cllpse


2 Answers

Not explicitly answering your question, but there are a number of open source FLV players in the wild. I'd approach the problem by grabbing one of those and seeing how they handle playing video.

FPlayer would be an excellent starting point. Here is the class that is doing the work. It is fairly straight forward, but using a project like this would probably save you some time.

This snippet should do the trick in an extremely bare bones fashion:

var vid:Video = new Video(320, 240);
addChild(vid);

var nc:NetConnection = new NetConnection();
nc.connect(null);

var ns:NetStream = new NetStream(nc);
vid.attachNetStream(ns);

var listener:Object = new Object();
listener.onMetaData = function(evt:Object):void {};
ns.client = listener;

ns.play("externalVideo.flv");

from here

like image 53
Joel Hooks Avatar answered Sep 28 '22 05:09

Joel Hooks


To do this locally - cut and paste the following code in the first frame of your flash file. Of course change the name at the end.

stage.displayState = StageDisplayState.FULL_SCREEN; 

var connection:NetConnection = new NetConnection();
var stream:NetStream;
var video:Video = new Video(1280,960);
var metaObj:Object = new Object();

function onMetaData(data:Object):void
{

}

connection.connect(null);
stream = new NetStream(connection);
stream.client = metaObj;
metaObj.onMetaData = onMetaData;
video.attachNetStream(stream);
addChild(video);
stream.play("name_of_flv.flv");
video.x = 0;
video.y = 0;
like image 40
user171699 Avatar answered Sep 28 '22 07:09

user171699