让我的外部NetStream工作 - 但如何从我的库中加载.flv?

时间:2014-09-23 11:17:58

标签: actionscript-3 flash video

如何将位于我的(内部)Flash库中的.flv(我们称之为#34; library.flv")加载到我的Netstream中?

我可以使用以下内容轻松加载外部.flv,但我需要从我的库中加载.flv

//Creating the video object
var ADFvideo = new Video(110,180);
videoContainer.addChild(ADFvideo);
ADFvideo.x = 0;
ADFvideo.y = 0;

//Loading the flv into the video object 
var ADFnc:NetConnection = new NetConnection();
ADFnc.connect(null);
var ADFns:NetStream = new NetStream(ADFnc);
ADFvideo.attachNetStream(ADFns);

//Handling metaData (it arrives as the video starts playing, so it is the pefect time to fire the first event);
var ADFcustomClient:Object = new Object();
ADFcustomClient.onMetaData = ADFmetaDataHandler;
ADFns.client = ADFcustomClient;
var ADFinfoObj:Object;
function ADFmetaDataHandler(ADFinfo:Object):void
{
        //meta stuff
}

ADFns.play("files/external.flv"); /* current way of loading the external .flv */

ADFns.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);

function statusChanged(stats:NetStatusEvent)
{
        //event changes
}

2 个答案:

答案 0 :(得分:1)

我认为您不能将NetStream与嵌入式flv视频一起使用。将视频导入库时,您可以选择将其转换为动画片段,或将其保存为位于时间轴上的简单视频。对于后面的选项,您无法创建AS链接。建议不要使用更长的剪辑,因为您会遇到同步问题,播放问题和预加载问题。

答案 1 :(得分:0)

您可以尝试对发布的代码进行此调整作为起点。使用3秒视频(H.263 / Sorenson)进行测试,宽度为1280宽度,高度为720,音频为44100hz 128,并且没有" ..经历缓慢的行为"在我身边有一台糟糕的试验机。

当视频结束时,您需要使用您的函数statusChanged(stats:NetStatusEvent)来处理接下来发生的事情(我已编辑代码以执行常量重播作为示例)

无论如何,这段代码意味着最终编译的SWF和FLV作为一个包存在。因此,200kb FLV将为输出SWF大小增加+ 200kb。请特别注意大/多FLV嵌入。

//// Specify embed item and create Class to store such item
[ Embed(source = "yourFileName.flv", mimeType = "application/octet-stream") ]
var bytes_FLV : Class; 
//// End embedded item setup

//create bytes for NStream from embedded item
var file_BA:ByteArray = new bytes_FLV(); 

//Creating the video object
var ADFvideo = new Video(110,180);
videoContainer.addChild(ADFvideo);
ADFvideo.x = 0;
ADFvideo.y = 0;

//Loading the flv into the video object 
var ADFnc:NetConnection = new NetConnection();
ADFnc.connect(null);
var ADFns:NetStream = new NetStream(ADFnc);
ADFvideo.attachNetStream(ADFns);

//Handling metaData (it arrives as the video starts playing, so it is the pefect time to fire the first event);
var ADFcustomClient:Object = new Object();
ADFcustomClient.onMetaData = ADFmetaDataHandler;
ADFns.client = ADFcustomClient;
var ADFinfoObj:Object;
function ADFmetaDataHandler(ADFinfo:Object):void
{
        //meta stuff
}

///ADFns.play("files/external.flv"); /* current way of loading the external .flv */

//Send file_BA to NStream for playback.. 
ADFns.play(null);
ADFns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);        
ADFns.appendBytes(file_BA);

ADFns.addEventListener(NetStatusEvent.NET_STATUS, statusChanged);

function statusChanged(stats:NetStatusEvent)
{
    //event changes
    //trace("NetStream Status : " + stats.info.code);

    if (stats.info.code == "NetStream.Buffer.Empty") 
    { 
        //Buffer.Empty = video has ended..
        ADFns.appendBytesAction(NetStreamAppendBytesAction.RESET_BEGIN);        
        ADFns.appendBytes(file_BA);

    }
}