Flash / ActionScript 3: Load .FLV file into a Movi

2020-02-10 08:07发布

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

5条回答
Lonely孤独者°
2楼-- · 2020-02-10 08:36

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

查看更多
我只想做你的唯一
3楼-- · 2020-02-10 08:36

As subha pointed out, its done using the NetStream class... however, that class in particular is quite hard to work with, and very uncoherent with the rest of the language...

I would strongly advice you to use some library, class or component to wrap it up. The FLVPlayback component in Flash (without any skins), in contrast with all the other built-in components in Flash, is really straight forward and very easy to use ;)

查看更多
▲ chillily
4楼-- · 2020-02-10 08:36
var video:Video = new Video();
addChild(video);

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

var ns:NetStream = new NetStream(nc);
ns.client = {};
ns.client.onMetaData = ns_onMetaData;
ns.client.onCuePoint = ns_onCuePoint;
ns.play("http://www.helpexamples.com/flash/video/cuepoints.flv");

video.attachNetStream(ns);

function ns_onMetaData(item:Object):void {
    trace("metaData");
    // Resize video instance.
    video.width = item.width;
    video.height = item.height;
    // Center video instance on Stage.
    video.x = (stage.stageWidth - video.width) / 2;
    video.y = (stage.stageHeight - video.height) / 2;
}

function ns_onCuePoint(item:Object):void {
    trace("cuePoint");
    trace(item.name + "\t" + item.time);
}
查看更多
Emotional °昔
5楼-- · 2020-02-10 08:37

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;
查看更多
啃猪蹄的小仙女
6楼-- · 2020-02-10 08:38
var flvPlaceHolder:MovieClip = new MovieClip();    

var vid:Video = new Video(320, 240);
flvPlaceHolder.addChild(vid);
addChild(flvPlaceHolder);
flvPlaceHolder.x = stage.stageWidth/2-vid.width/2;
flvPlaceHolder.y = stage.stageHeight/2-vid.height/2;

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("mario.flv");
查看更多
登录 后发表回答