Indigo Rose Software

Professional Software Development Tools

 
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2008
    Location
    UK
    Posts
    5

    Audio display elapsed time

    Hello, i used the following code to display elapsed time of the song, it is working, but i have a problem - on select song in listbox (without playing it), the paragraph displays this: 0-1:59 ..... Well, once i play the song, it dissapears and the right timing is starting.


    current = Audio.GetCurrentPos(CHANNEL_BACKGROUND);
    length = Audio.GetLength(CHANNEL_BACKGROUND);
    current_minutes = Math.Floor(current / 60);
    current_seconds = Math.Floor(current - (current_minutes*60));
    length_minutes = Math.Floor(length/60);
    length_seconds = Math.Floor(length - (length_minutes*60));

    if current_minutes < 10 then
    current_minutes = "0" .. current_minutes;
    end

    if current_seconds < 10 then
    current_seconds = "0" .. current_seconds;
    end

    if length_minutes < 10 then
    length_minutes = "0" .. length_minutes;
    end

    if length_seconds < 10 then
    length_seconds = "0" .. length_seconds;
    end

    sTime = current_minutes .. ":" .. current_seconds ;
    Paragraph.SetText("Paragraph2", sTime);


    Can anyone please help me with this? I'm just an amateur
    Thanks a lot

  2. #2
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    Before doing any math, you should check if no error occurred while retrieving the values for GetCurrentPos and GetLength. In the case of an error, the functions return -1. If you ignore the error and just do the conversions you end up with the display of 0-1:59.

    Ulrich

  3. #3
    Join Date
    Jul 2008
    Location
    UK
    Posts
    5
    Oh, thank you ... it sounds a bit confusing for me though, how can i do that? with a code like Application.GetLastError?

  4. #4
    Join Date
    Apr 2005
    Location
    São Paulo, Brazil
    Posts
    2,539
    All you have to do is test the value returned before proceeding... Like this:
    Code:
    current = Audio.GetCurrentPos(CHANNEL_BACKGROUND);
    length = Audio.GetLength(CHANNEL_BACKGROUND);
    if ((current ~= -1 ) and (length ~= -1)) then
        -- both values are different to -1 and should be valid, continue processing
        current_minutes = Math.Floor(current / 60); 
        current_seconds = Math.Floor(current - (current_minutes*60)); 
        length_minutes = Math.Floor(length/60); 
        length_seconds = Math.Floor(length - (length_minutes*60));
        -- place the rest of the former code here...
    else
        -- oops, an error occurred, show a static value instead
        Paragraph.SetText("Paragraph2", "00:00");
    end
    By doing this simple comparison, you'll make sure you won't display nonsense.

    Ulrich

  5. #5
    Join Date
    Jul 2008
    Location
    UK
    Posts
    5
    thank you very much Ulrich

    yes, it works now - just a small exception, when i play the song, displays the 0-1:59 for a very short time before showing the right timing.

Similar Threads

  1. Play seperate audio and movieclip at the same time?
    By spansk in forum AutoPlay Media Studio 6.0
    Replies: 3
    Last Post: 09-09-2006, 04:21 AM
  2. Build failure because of errors
    By Ed Stanley in forum AutoPlay Media Studio 6.0
    Replies: 2
    Last Post: 02-07-2006, 03:51 PM
  3. Using a slider to show audio posiion in time
    By Randy3265 in forum AutoPlay Media Studio 5.0
    Replies: 16
    Last Post: 01-07-2006, 08:34 AM
  4. how to display real time clock
    By mhike in forum AutoPlay Media Studio 5.0
    Replies: 2
    Last Post: 09-01-2005, 04:08 PM
  5. Display System Time in Project
    By Mythwyn in forum AutoPlay Media Studio 5.0
    Replies: 5
    Last Post: 12-27-2003, 09:53 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts