I need to make a dynamic text field display Sound.duration like 1:30sec instead of 90sec (for exemple…).
I was not a maths major… I studied that long ago… I think… But I have no clue…
seconds = 90;
minutes = (Math.floor(seconds/60)) + “:” + (seconds%60);
Sbeener, will you marry me?
I kinda remember that “floor” thing from ASDG but I couldn’t remember its name…
ok, so I got that from what you gave me:
var totTimeMin, totTimeSec, elapsTimeMin, elapsTimeSec;
totTimeMin = Math.floor(Math.round(_root.mp3.duration/1000)/60);
totTimeSec = Math.round(_root.mp3.duration/1000)%60;
elapsTimeMin = Math.floor(Math.round(_root.mp3.position/1000)/60);
elapsTimeSec = Math.round(_root.mp3.position/1000)%60;
if (stopped != true) {
totalTime = totTimeMin+":"+totTimeSec;
elapsTime = elapsTimeMin+":"+elapsTimeSec;
remaiTime = (totTimeMin-elapsTimeMin)+":"+(totTimeSec-elapsTimeSec);
}
Now, I know I’m totally getting advantage of your generosity here but… Is there a way to get some leading zeros there like: “00:04” instead of “0:4”… Again, only if you have the free time… THX!
ps: I making a simple music player interface…
// define this function somewhere...
function millisecondsToMinutes(msec){
var m = Math.floor(msec/60000);
var s = Math.floor(msec%60000 / 1000);
if(s<10) s = "0" + s;
return m + ":" + s;
}
// then this code to find the times...
if(!stopped){
var t = _root.mp3.duration;
var p = _root.mp3.position;
totalTime = millisecondsToMinutes(t);
elapsTime = millisecondsToMinutes(p);
remaiTime = millisecondsToMinutes(t-p);
}
so i the code to parse the milliseconds to a conventional time format into a function. this made the code to build the display a little cleaner.
adding the zero is handled with a simple if statement, you could do the same for the minutes if you like.
ok, you’re the man…
I’m definitly trying to go through your code slowly to learn from it… I know my code is so messy… the if (!stopped) looks so much sexyer than if (stopped != true)… How did you learn to code? I want to get there but my maths sucks… like the modulo thing… I remember reading about it but I could never have come up with little equation thing to get the time… Ho well I got Rob Penners book (it’s pretty amazing so far, very insightfull guy…) and I’m awaiting the MX version of Mook’s ASDG… Anything else you’d recommend?
as far as the code, I thought the millisecond looked cool so I modified your code slightly like that:
function millisecondsToMinutes(msec) {
var m = Math.floor(msec/60000);
var s = Math.floor(msec%60000/1000);
var ms = Math.floor(msec%100);
if (s<10) {
s = "0"+s;
}
if (m<10) {
m = "0"+m;
}
if (ms<10) {
ms = "0"+ms;
}
return m+":"+s+":"+ms;
}
and it seems to work fine… I tried to understand the modulo thing from your exemple but I’m not %100 clear about how it works… I should never have studied music in college!!
Anyway, the site is almost done and I’ll let you know about it if you wanna see what it was all about THX!
robert penner’s pretty brilliant. apparently brendan hall’s book on oop actionscript is good too. it’s not fundamentals, it’s higher level stuff, but it never hurts to get off on the right foot.
modulo means take the remainder when i divide the left side by the right side. so:
14%3 = 2
because
14 / 3 = 4 with a remainder of 2
i learned my coding through the internet and experimentation (and a few things from kirupa.com too!). there’s a great tutorial on oop online courtesy of robin debruiel. that catapulted my abilities significantly and some day i hope to repay him for that.
i studied music in college too, percussion major. nice cd collection incidentally.
cheers.
is that what you’re talking about?
http://www.debreuil.com/docs/ch01_Intro.htm
a far as cd collection, if you have access to a Mac, you have life account on my carracho server!
*Originally posted by sbeener *
**
i learned my coding through the internet and experimentation (and a few things from kirupa.com too!). there’s a great tutorial on oop online courtesy of robin debruiel. that catapulted my abilities significantly and some day i hope to repay him for that.
i studied music in college too, percussion major. nice cd collection incidentally.
cheers. **
I learned from this website as well.
that’s the one - debreuil. pardon my previous spelling. i received some top notch advice from the message board there too, highly recommended.
malheursement, i don’t use a mac. there’s a few kicking around the office though, maybe i’ll give it a try on one of those.