Hey ! i am really depressed and need to get on with my problem. I have a mp3 file and I want it to play, and while its playing the time should be displayed in 2 textfields. in the first its the current time and in the second the whole duration in minutes and seconds.
i tried forum-tipps, google everything and this is what I have. I am working in AS3
var playback_min:uint;
var playback_sec:uint;
var total_min:uint;
var total_sec:uint;
var positionTimer:Timer;
var estimated_length:int;
var sound:Sound = new Sound();
var soundURL:URLRequest = new URLRequest("BG.mp3");
sound.load(soundURL);
var channel:SoundChannel = new SoundChannel();
channel = sound.play();
positionTimer = new Timer(50);
positionTimer.addEventListener(TimerEvent.TIMER,positionTimerHandler);
positionTimer.start();
function positionTimerHandler(event:TimerEvent):void
{
var load_time:Number = sound.bytesLoaded / sound.bytesTotal;
estimated_length = Math.ceil( sound.length / load_time );
playback_min = Math.floor( ( channel.position * 0.001 ) / 60);
playback_sec = Math.floor( ( channel.position * 0.001 ) % 60);
total_min = Math.floor( ( estimated_length * 0.001 ) / 60 );
total_sec = Math.floor( ( estimated_length * 0.001 ) % 60 );
time_txt.text = pad_zero(playback_min) + "." + pad_zero(playback_sec);
full_txt.text = pad_zero(total_min) + "." + pad_zero(total_sec);
}
function pad_zero( str_to_pad:Number ):String
{
if(str_to_pad < 10)
return "0" + str_to_pad;
else
return String( str_to_pad );
}
THANK YOU ALL IN ADVANCE !! ((: