所以我们有flv文件,我们用mx:vidodisplay播放它。如何确定我们目前在哪个流框架上?
答案 0 :(得分:2)
您可以在流元数据中检查最接近当前时间的关键帧
的 UPD 强>
在创建流时,您需要处理其“onMetaData
调用:
private var metaInfo: Object;
private function initStream():void{ stream = new NetStream(conn); stream.bufferTime = 5; stream.addEventListener(NetStatusEvent.NET_STATUS, onStatus); stream.client = new Object(); stream.client.onMetaData = onMetaData;/*this is what you need*/ video.attachNetStream(stream); } private function onMetaData(info:Object):void { metaInfo = info; var tmpstr:String = ''; for(var s:String in info){ var tstr:String = s + ' = ' + info[s] + '\n'; tmpstr += tstr.indexOf('object') == -1 ? tstr : ''; for(var a:String in info[s]){ var ttstr:String = s + ':' + a + ' = ' + info[s][a] + '\n'; tmpstr += ttstr.indexOf('object') == -1 ? ttstr : ''; for(var c:String in info[s][a]){ var tttstr:String = s + ':' + a + ':' + c + ' = ' + info[s][a][c] + '\n'; tmpstr += tttstr.indexOf('object') == -1 ? tttstr : ''; } } } trace(tmpstr); }
在此跟踪中,您将看到流的元数据是否包含以下项目:
征求点:93:偏移= 10342550
征求点:93:时间= 165.799
或者可能:
关键帧:次= 0,0.48,0.96,1.44,1.92,2.4,2.88,3.36,3.84,4.32,4.8,5.28,5.76,6.24
关键帧:filepositions = 1063,95174,136998,176043,209542,239148,271062,302006,331724,363948,395039,427503,456317,483313
它取决于编码器设置,如果您的元数据有任何此类对象(metadata['keyframes']
,metadata['seekpoints']
等),您可以执行以下操作:
for (var i:int = 0; i < metaInfo['keyframes']['times'].length; i++) {
if (stream.time < metaInfo['keyframes']['times'][i]) {
var keyFrameNum: int = (metaInfo['keyframes']['times'][i] - stream.time < stream.time - metaInfo['keyframes']['times'][i - 1]) ? i : i - 1;
}
}
答案 1 :(得分:0)
我做了一个静态类来将netstream元数据对象解析为as3对象。您可以使用JSON.stringify(parse(info))来检查info中的所有属性。本课程只是草稿实施。可能是里面的一些错误。
public class NetStreamMetaData
{
public static function parse(object:Object, isArray:Boolean = false):Object{
var ret:Object = {};
if(isArray)
ret = [];
var k:String;
for(k in object){
if(isNaN(Number(k))){
if(object[k] is Array){
ret[k] = parse(object[k], true);
}else{
ret[k] = object[k];
}
}else{
if(object[k] is Array){
ret.push(parse(object[k], false));
}else{
ret.push(object[k]);
}
}
}
return ret;
}
}