简体   繁体   English

Flash / ActionScript 3:将.FLV文件加载到MovieClip中并开始播放该FLV文件

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

如何将FLV文件加载到MovieClip中(让我们调用实例“flvPlaceHolder”)并开始播放该FLV文件..使用ActionScript 3?

Not explicitly answering your question, but there are a number of open source FLV players in the wild. 没有明确回答你的问题,但是野外有许多开源FLV播放器。 I'd approach the problem by grabbing one of those and seeing how they handle playing video. 我通过抓住其中一个并看到他们如何处理播放视频来解决问题。

FPlayer would be an excellent starting point. FPlayer将是一个很好的起点。 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 从这里

To do this locally - cut and paste the following code in the first frame of your flash file. 要在本地执行此操作 - 将以下代码剪切并粘贴到Flash文件的第一帧中。 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;
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);
}

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... 正如subha指出的那样,它使用NetStream类完成...但是,特别是那个类很难处理,并且与语言的其余部分非常不一致......

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 ;) 与Flash中的所有其他内置组件相比,Flash中的FLVPlayback组件(没有任何外观)非常简单易用;)

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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM