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

1. ## how to calculate minutes and seconds from media file in j2me

how to calculate minutes and seconds from media file in j2me

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

4. ## 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. ## Re: how to calculate minutes and seconds from media file in j2me

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. ## 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. ## 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. ## 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. ## Re: how to calculate minutes and seconds from media file in j2me

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. ## 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
•