Posted By

nate63179 on 11/03/09


Tagged

flash as3 utils timecode


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mali
adrianparr


Flash: convert milliseconds to timecode


 / Published in: ActionScript 3
 

Handy function for converting milliseconds to video timecode

  1. /**
  2. * Converts millisecond figure into timecode
  3. * @param millisecond total number of milliseconds - accurate up to one hour
  4. */
  5. public static function toTimeCode(milliseconds:int) : String {
  6. var isNegative:Boolean = false;
  7. if (milliseconds < 0) {
  8. isNegative = true;
  9. milliseconds = Math.abs(milliseconds);
  10. }
  11.  
  12. var seconds:int = Math.round((milliseconds/1000) % 60);
  13. var strSeconds:String = (seconds < 10) ? ("0" + String(seconds)) : String(seconds);
  14. if(seconds == 60) strMinutes = "00";
  15. var minutes:int = Math.round(Math.floor((milliseconds/1000)/60));
  16. var strMinutes:String = (minutes < 10) ? ("0" + String(minutes)) : String(minutes);
  17.  
  18. if(minutes > 60) {
  19. strSeconds = "60";
  20. strMinutes = "00";
  21. }
  22.  
  23. var timeCodeAbsolute:String = strMinutes + ":" + strSeconds;
  24. var timeCode:String = (isNegative) ? "-" + timeCodeAbsolute : timeCodeAbsolute;
  25. return timeCode;
  26. } // end toTimeCode

Report this snippet  

You need to login to post a comment.