Media player plugin: currentime/totaltime

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts
  • gnetcanada
    Indigo Rose Customer
    • May 2003
    • 83

    Media player plugin: currentime/totaltime

    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
    Indigo Rose Staff Member
    • Jul 2003
    • 710

    #2
    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!

    Code:
    --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;

    Comment

    • gnetcanada
      Indigo Rose Customer
      • May 2003
      • 83

      #3
      thanks desmond i will try that out.

      Comment

      • pixel-kraft
        Indigo Rose Customer
        • Jan 2004
        • 15

        #4
        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

        Comment

        Working...
        X