Show elapsed time and total time of a song with Flash AS3
This movie requires Flash Player 9
[download id=»3″ format=»2″]
Código del ejemplo
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
import flash.media.Sound; import flash.events.Event; import flash.media.SoundChannel; var cancion:Sound = new Sound(); var canal:SoundChannel = new SoundChannel(); playStop.addEventListener(MouseEvent.CLICK, onPlayStop); playStop.useHandCursor = true; cancion.addEventListener(Event.COMPLETE, onComplete); cancion.load(new URLRequest("papdance_produced_by_xavirobot_with_fruityloops.mp3")); function onFrame(e:Event):void { //Code by xavirobot var p:uint = canal.position; //Posicion actual de la cancion en horas, minutos, segundos, y centesimas tc.text = "Current time: "; tc.appendText(String(((p -(Math.floor(p/216000000)*216000000))/3600000)+100).substr(1,2)+":"); tc.appendText(String(((p -(Math.floor(p/3600000)*3600000))/60000)+100).substr(1,2)+":"); tc.appendText(String(((p -(Math.floor(p/60000)*60000))/1000 )+100).substr(1,2)+":"); tc.appendText(String(((p -(Math.floor(p/1000)*1000))/10)+100).substr(1,2)); } function onPlayStop(e:Event = null):void { if (playStop.label == "Play") { playStop.label = "Stop"; canal = cancion.play(); addEventListener(Event.ENTER_FRAME,onFrame); }else{ playStop.label = "Play"; canal.stop(); removeEventListener(Event.ENTER_FRAME,onFrame); } } function onComplete(e:Event):void { var p:uint = cancion.length; //Tiempo total de la cancion en horas, minutos, segundos, y centesimas tt.text = "Total time: "; tt.appendText(String(((p -(Math.floor(p/216000000)*216000000))/3600000)+100).substr(1,2)+":"); tt.appendText(String(((p -(Math.floor(p/3600000)*3600000))/60000)+100).substr(1,2)+":"); tt.appendText(String(((p -(Math.floor(p/60000)*60000))/1000 )+100).substr(1,2)+":"); tt.appendText(String(((p -(Math.floor(p/1000)*1000))/10)+100).substr(1,2)); } |
Social Report xavirobot
One comment on “AS3 – Audio – Mostrar el tiempo transcurrido y el tiempo total de una cancion con flash”
Estupendo ejemplo, he estado buscando por ahi y de todos este es el mas corto y optimizado que he encontrado, solo una cosa podrias crear una clase y sacarlo fuera a modo de utilidad.
Gracias por el código.