×

Discussion Board

Results 1 to 10 of 10
  1. #1
    Registered User
    Join Date
    Dec 2008
    Posts
    9

    Question how to calculate minutes and seconds from media file in j2me

    how to calculate minutes and seconds from media file in j2me

  2. #2
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: how to calculate minutes and seconds from media file in j2me

    Not quite sure what you're after...

    Code:
    // create a player for the media file
    Player player = Manager.createPlayer(FILENAME);
    
    // you might not get meaningful results until the player is prefetched
    player.prefetch();
    
    // these might not return meaningful values for all media files
    
    // total length in milliseconds
    long duration = player.getDuration();
    
    // current player time in milliseconds
    long currentTime = player.getMediaTime();
    You might get zero or TIME_UNKNOWN if the Player cannot determine the length of the media.

  3. #3
    Registered User
    Join Date
    Dec 2008
    Posts
    9

    Question Re: how to calculate minutes and seconds from media file in j2me

    I know the below code but, its not my question. My question is suppose the media is of duration 66000000 millisec. Now i want to show it in this format --> mm:ss--> 01:06. how to calculate minutes and seconds from it.
    Last edited by awadbensaleh; 2008-12-20 at 07:09.

  4. #4
    Super Contributor
    Join Date
    Jan 2008
    Location
    Amravati, India
    Posts
    546

    Re: how to calculate minutes and seconds from media file in j2me

    Code:
    long TimeInMilliseconds;
    //Code here to get TimeInMilliseconds
    
    int MM, SS;
    MM = (int)(TimeInMilliseconds / 60000);
    SS = (int)(TimeInMilliseconds / 1000) % 60;
    
    //Code to print MM:SS here
    You may also round 500 milliseconds to 1 second like this...

    Code:
    long TimeInMilliseconds;
    //Code here to get TimeInMilliseconds
    
    int MM, SS;
    MM = (int)((TimeInMilliseconds + 500) / 60000);
    SS = (int)((TimeInMilliseconds + 500) / 1000) % 60;
    
    //Code to print MM:SS here
    Tell me if you want Code to print MM:SS also...

  5. #5
    Registered User
    Join Date
    Dec 2008
    Posts
    9

    Question Re: how to calculate minutes and seconds from media file in j2me

    Please help me out.....

    I Apologize arpit2agrawal and grahamhughes if i m wrong is explaining my doubt.

    I will explain it again.

    suppose a media file is of duration 1 minute and 6 seconds. i.e; 01:06

    If i use the method getDuration it gives the duration in milliseconds.

    example i have a media file of duration 66000000 milliseconds i.e; 01:06 .

    how to calculate and show the user that 66000000 milliseconds is 1 minute and 6 seconds....

  6. #6
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: how to calculate minutes and seconds from media file in j2me

    arpit2agrawal's answer is precisely what you are asking for.

    I'll add that 1:06 is 66000 milliseconds, not 66000000.

  7. #7
    Registered User
    Join Date
    Dec 2008
    Posts
    9

    Question Re: how to calculate minutes and seconds from media file in j2me

    Yes you are rite but it is not giving the exact result. it is in the format 1:6 i want the
    same in the format 01:06.

    Here is the code below i got but i m unable to understand by the second line ,why he is dividing with 1000000.

    long time =66000000;
    time = time / 1000000;
    String strTime = "" + (time % 10);
    time = time / 10;
    strTime = (time % 6) + strTime;
    time = time / 6;
    strTime = (time % 10) + ":" + strTime;
    time = time / 10;
    strTime = (time % 6) + strTime;
    time = time / 6;

    System.out.println("time::"+strTime);

  8. #8
    Super Contributor
    Join Date
    Jun 2003
    Location
    Cheshire, UK
    Posts
    7,395

    Re: how to calculate minutes and seconds from media file in j2me

    Because this code is to convert microseconds, not milliseconds.

    Try changing the 1000000 to 1000.

  9. #9
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: how to calculate minutes and seconds from media file in j2me

    Hi awadbensaleh,

    you should at least try to play a bit with the code provided on previous answers: if you want a zero appended to hour/minute value when they are less than 10, then it'll be enough to place an if{} block in your code, and it'll be done

    Pit

  10. #10
    Registered User
    Join Date
    Dec 2008
    Posts
    9

    Talking Re: how to calculate minutes and seconds from media file in j2me

    Thanks allot to all dear participants.........

Posting Permissions

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