在文本字段中显示flv的维度

时间:2014-03-21 12:12:26

标签: actionscript-3 flash flash-cs5 flv flvplayback

以下是我的基本代码,即使用flvplayback加载flv视频。

我需要强制使用flvplayback的功能。

我已成功加载了flv视频。

现在我很难在文本字段中显示源视频文件的原始尺寸。

如何从这里继续前进。请指导我......

stage.displayState = StageDisplayState.FULL_SCREEN;
stage.align = StageAlign.TOP_LEFT;
stage.scaleMode = StageScaleMode.NO_SCALE;

import fl.video.*;

stop();

var rmys01:FLVPlayback = new FLVPlayback();
rmys01.source = "rhym01.flv";
rmys01.skin = "MinimaFlatCustomColorPlayBackSeekCounterVolMute.swf";
rmys01.autoPlay = true;
rmys01.fullScreenTakeOver = false;
rmys01.scaleMode = "maintainAspectRatio";
rmys01.setSize((stage.stageWidth/1.03), (stage.stageHeight/1.03));
rmys01.x = (stage.stageWidth/2)  - (rmys01.width/2);
rmys01.y = (stage.stageHeight/1.1) - (rmys01.height/1.1);
addChild(rmys01);
setChildIndex(rmys01,1);

1 个答案:

答案 0 :(得分:0)

您是否为NetStream设置了客户端?因为,一切正常。

以下是一个例子:

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

var ns:NetStream = new NetStream(nc);
var client: Object = {};
client.onMetaData = function(data:Object):void{
    //Display width and height
    var textField: TextField = new TextField();
    textField.autoSize = TextFieldAutoSize.LEFT;
    textField.defaultTextFormat = new TextFormat("Arial", 28);
    textField.text = "Width: " + data.width + ", Height: " + data.height;
    addChild(textField);
}
ns.client = client;
ns.play("path/to/Video");

var myVideo:Video = new Video();
myVideo.attachNetStream(ns);
addChild(myVideo);

出于调试目的,将跟踪(trace("There is MetaData!");)放在onMetaData处理程序上,检查是否触发。

对于FLVPlayback,您应订阅VideoEvent.READY

rmys01.addEventListener(VideoEvent.READY, onReady);

function onReady(e:VideoEvent):void {
    trace("READY");
    var flvPlayback:FLVPlayback = e.target as FLVPlayback;
    var metaData:Object = flvPlayback.metadata as Object;
    trace("height: "+metaData.height);
    trace("width: "+metaData.width);
    trace("duration: "+metaData.duration);
}

如果您在Flash IDE中进行编码,则VideoEvent会出现问题,因此您应该使用完全限定的类(fl.video.VideoEvent),否则,IDE会尝试将其解析为flash.events.VideoEvent

rmys01.addEventListener(fl.video.VideoEvent.READY, onReady);

function onReady(e:fl.video.VideoEvent):void {
    //Handler code
}