6 Replies Latest reply: Mar 28, 2012 3:38 AM by Venkom RSS

    video duration

    Venkom Community Member

      How to get video duration in as3 ?

        • 1. Re: video duration
          Andrei1 Community Member
          • 2. Re: video duration
            Venkom Community Member

            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

            • 3. Re: video duration
              Andrei1 Community Member

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

               

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

              • 4. Re: video duration
                Venkom Community Member

                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;

                }

                 

                • 5. Re: video duration
                  Andrei1 Community Member

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

                  • 6. Re: video duration
                    Venkom Community Member

                    Now total time fine, playing fine.

                     

                    Thank you