Skip to main content
Inspiring
October 24, 2011
Answered

video duration

  • October 24, 2011
  • 1 reply
  • 1718 views

How to get video duration in as3 ?

This topic has been closed for replies.
Correct answer Andrei1-bKoviI

I changed this total duration of video.

but some issus

msg is

Scene 1, Layer 'Actions', Frame 1, Line 5091067: 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;

}


You declared hours2, minutes2,etc. as Numbers but attempt to use them as Strings - hence the error.

1 reply

Inspiring
October 24, 2011
Inspiring
October 25, 2011

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

Inspiring
October 25, 2011

Use Date() and RegExp to do that. I have a tutorial on my blog:

http://as3-blog.net/?p=163