Copy link to clipboard
Copied
How to get video duration in as3 ?
You declared hours2, minutes2,etc. as Numbers but attempt to use them as Strings - hence the error.
Copy link to clipboard
Copied
NetStream invokes onMetaData() method - when it does - you can read video info including duration:
Copy link to clipboard
Copied
function formatTime(t:int):String {
var s:int = Math.round(t);
var m:int = 0;
if (s > 0) {
while (s > 59) {
m++;
s -= 60;
}
return String((m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s);
} else {
return "00:00";
}
}
How to add hours to above script.
Format : HH:MM:SS
Copy link to clipboard
Copied
Use Date() and RegExp to do that. I have a tutorial on my blog:
Copy link to clipboard
Copied
I changed this total duration of video.
but some issus
msg is
Scene 1, Layer 'Actions', Frame 1, Line 509 | 1067: Implicit coercion of a value of type String to an unrelated type Number. |
var newMeta:Object = new Object();
newMeta.onMetaData = onMetaData;
var vFrame:MovieClip=new MovieClip();
this.addChild(vFrame);
vFrame.addEventListener(Event.ENTER_FRAME, videoStatus);
function onMetaData(newMeta:Object):void
{
duration = newMeta.duration;
var hours2:Number;
var minutes2:Number;
var seconds2:Number;
var durminutes = duration/60;
hours2 = Math.floor(durmin/60);
if (duration>=3600) {
minutes2 = Math.floor(durmin%60);
} else {
minutes2 = Math.floor(duration/60);
}
seconds2 = Math.floor(duration%60);
if (hours2<10) {
hours2 = "0"+hours2;
}
if (minutes2<10) {
minutes2 = "0"+minutes2;
}
if (seconds2<10) {
seconds2 = "0"+seconds2;
}
trace (hours2+":"+minutes2+":"+seconds2);
}
function videoStatus():void
{
amountLoaded = ns.bytesLoaded/ns.bytesTotal;
controls.seekbar.loadBar.width = amountLoaded*330;
controls.seekbar.scrubber.x = ns.time/duration*320;
}
Copy link to clipboard
Copied
You declared hours2, minutes2,etc. as Numbers but attempt to use them as Strings - hence the error.
Copy link to clipboard
Copied
Now total time fine, playing fine.
Thank you