PDA

View Full Version : Media player plugin: currentime/totaltime



gnetcanada
02-11-2004, 07:19 PM
Hi,

Right now im using the page timer at 1000ms to update the Media player object, however it is displaying the current and total time in a stupid seconds only format, does anyone have code to display in the 0:00/0:00 format?

Right now this is what i got:
length = MediaPlayer.GetLength("mediaplayer");
pos = MediaPlayer.GetCurrentPos("mediaplayer");
msg = string.format("%.2f/%.2f",pos,length);
Label.SetText("msg",msg);

And it displays
1.34343/223.1121 (seconds over seconds with a huge decimal) i would like something more like winamp.

Any ideas?

Shawn

Desmond
02-13-2004, 08:13 AM
Hello Shawn,

I use something along these lines (see below). As far as having the actions output in seconds-only format . . . while it makes it a little harder to output the time in a pleasing format, there are other instances where a 00:00 format would be impractical.

Enjoy!



--What is the currently playing track?
currenttrack = CDAudio.GetTrack();

--What is the current position of the track?
current = CDAudio.GetCurrentPos();

--What is the total length of the current track?
length = CDAudio.GetTrackLength(currenttrack);

--Split the current position into minutes and seconds, no decimal
current_minutes = Math.Floor(current/60); --get the current position (minutes)
current_seconds = Math.Floor(current - (current_minutes*60)); --get the current position (seconds)

--Split the current length into minutes and seconds, no decimal
length_minutes = Math.Floor(length/60); --get the length (minutes)
length_seconds = Math.Floor(length - (length_minutes*60)); --get the length (seconds)

--If minutes is less than 10, add a preceding zero (current position)
if current_minutes < 10 then --format the minutes to 'always' double digit
current_minutes = "0" .. current_minutes;
end

--If seconds is less than 10, add a preceding zero (current position)
if current_seconds < 10 then --format the seconds to 'always' double digits
current_seconds = "0" .. current_seconds;
end

--if minutes is less than 10, add a preceding zero (length)
if length_minutes < 10 then --format the minutes to 'always' double digit
length_minutes = "0" .. length_minutes;
end

--if seconds is less than 10, add a preceding zero (length)
if length_seconds < 10 then --format the seconds to 'always' double digits
length_seconds = "0" .. length_seconds;
end

--set sTime to contain time in format 00:00 / 00:00
sTime = current_minutes .. ":" .. current_seconds .. " / " .. length_minutes .. ":" .. length_seconds;

gnetcanada
02-13-2004, 08:32 AM
thanks desmond i will try that out.

pixel-kraft
02-16-2004, 02:45 PM
Great, great, great.

I just searced for a way to show the mediaplayer time in that format. I found it here. It works very well

THANXS Desmond