2011-05-25 129 views
1

我想用AS3顯示FLV電影的持續時間。我不斷收到元數據錯誤。下面的代碼。謝謝。用AS3顯示FLV的持續時間

stop(); 


// Video setup -----------------------------------------------/ 
var nc:NetConnection = new NetConnection(); 
nc.connect(null); 

var ns:NetStream = new NetStream(nc); 
ns.addEventListener(NetStatusEvent.NET_STATUS, onStatus); 
ns.client = this; 
video.attachNetStream(ns); 

function onStatus(e:Object):void 
{ 
    if(e.info.code == "NetStream.Play.Start" || 
     e.info.code == "NetStream.Buffer.Full") empty.visible = false; 

    else if(e.info.code == "NetStream.Buffer.Empty") empty.visible = true; 

    else if(e.info.code == "NetStream.Play.Stop") ns.seek(0); 
} 

// Get duration ---------------------------------------------/ 

var dur:Number; 
var duration:Number; 

function onMetaData(meta:Object) 
{ 
    dur = meta.duration; 
} 

// Play the video -------------------------------------------/ 
ns.play("http://adobe.edgeboss.net/download/adobe/adobetv/flasher_magazine/issue_1/issue1.mp4"); 

// Progress bar ---------------------------------------------/ 
addEventListener(Event.ENTER_FRAME, loop); 

thebar.progress.scaleX = 0; 

function loop(e:Event):void 
{ 
    thebar.loaded.scaleX = ns.bytesLoaded/ns.bytesTotal; 
    if(dur) 
    { 
     thebar.progress.scaleX = ns.time/dur; 
    } 

} 

thebar.loaded.addEventListener(MouseEvent.CLICK, seekTo); 


thebar.loaded.buttonMode = true; 
thebar.progress.mouseEnabled = false; 

function seekTo(e:Event):void 
{ 
    ns.seek((thebar.track.mouseX/thebar.track.width) * dur); 
} 


// play/pause control ---------------------------------------------/ 
playPause.buttonMode = true; 
playPause.addEventListener(MouseEvent.CLICK, playPauseClick); 
playPause.addEventListener(MouseEvent.ROLL_OVER, playPauseOver); 
playPause.addEventListener(MouseEvent.ROLL_OUT, playPauseOut); 

function playPauseClick(e:MouseEvent):void 
{ 
    var c:MovieClip = playPause; 
    if(c.currentFrame == 10) 
    { 
     c.gotoAndStop(30); 
     ns.pause(); 
    } 
    else if(c.currentFrame == 30) 
    { 
     c.gotoAndStop(10); 
     ns.resume(); 
    } 
} 

function playPauseOver(e:MouseEvent):void 
{ 
    var c:MovieClip = playPause; 
    if(c.currentFrame == 1) 
    { 
     c.gotoAndStop(10); 
    } 
    else if(c.currentFrame == 20) 
    { 
     c.gotoAndStop(30); 
    } 
} 

function playPauseOut(e:MouseEvent):void 
{ 
    var c:MovieClip = playPause; 
    if(c.currentFrame == 10) 
    { 
     c.gotoAndStop(1); 
    } 
    else if(c.currentFrame == 30) 
    { 
     c.gotoAndStop(20); 
    } 
} 

// Timer -----------------------------------------------/ 

var time_interval:Number = setInterval(checkTime, 500, ns); 
function checkTime(myVideo_ns:NetStream) { 
var ns_seconds:Number = myVideo_ns.time; 
var minutes:Number = Math.floor(ns_seconds/60); 
var seconds = Math.floor(ns_seconds%60) 
if (seconds<10) { 
seconds = ("0"+seconds); 
} 
time_txt.text = minutes+":"+seconds; 
}; 

//non working duration code 
ns.onMetaData = function(metadata) { 
    duration = metadata.duration; 
    var dur_seconds:Number = duration; 
    var minutes_dspl = Math.floor(dur_seconds/60); 
    var seconds_dspl = Math.floor(dur_seconds%60); 
    if (minutes_dspl<10) { 
     minutes_dspl = ("0"+minutes_dspl); 
    } 
    if (seconds_dspl<10) { 
     seconds_dspl = ("0"+seconds_dspl); 
    } 
    duration_txt.text = minutes_dspl+":"+seconds_dspl; 
}; 

回答

2

您指定的NetStream客戶端是這個的頭部進行編碼,所以你需要給onMetaData方法添加到這個爲好。

變化//非工作時間的代碼

function onMetaData(metadata:Object) { 
    duration = metadata.duration; 
    var dur_seconds:Number = duration; 
    var minutes_dspl = Math.floor(dur_seconds/60); 
    var seconds_dspl = Math.floor(dur_seconds%60); 
    if (minutes_dspl<10) { 
     minutes_dspl = ("0"+minutes_dspl); 
    } 
    if (seconds_dspl<10) { 
     seconds_dspl = ("0"+seconds_dspl); 
    } 
    duration_txt.text = minutes_dspl+":"+seconds_dspl; 
}; 

,並刪除之前的調用onMetaData功能

+0

這做到了!謝謝。 – cbeezy 2011-05-25 18:27:29

0

您沒有發佈錯誤,但我會假設錯誤是由於您對視頻的編碼造成的。
元數據在視頻

相關問題