Android MediaKlayer SDK not working correctly

I have an mp3 file, and my application should look for some selected time of this mp3 file, and then start playing from there.

I convert my string time with this method to int value

private static int convert(String time) { int quoteInd = time.indexOf(":"); int pointInd = time.indexOf("."); int min = Integer.valueOf(time.substring(0, quoteInd)); int sec = Integer.valueOf(time.substring(++quoteInd, pointInd)); int mil = Integer.valueOf(time.substring(++pointInd, time.length())); return (((min * 60) + sec) * 1000) + mil; } 

Note: my bites are like this 5:12.201 , which means 5 minutes and 12 seconds and 201 milliseconds.

I got these times from the MP3 Audio Editor application (this is for windows) and I checked the theme with the KMPlayer application (this is for windows). And these times were right for both of them.

But in my application, when I search for my MediaPlayer , by this time the sound does not start from the position I have chosen. (The time is right, but the sound is different.)


I thought MediaPlayer not right at this time. So I checked the current position by calling getCurrentPosition() before playing, but the return value and the sought value were the same.

I have no idea about this.


Edit:

My problem is not time conversion.

I convert and search there correctly, but he plays what was not expected at this time.

This means that the time is different in KMPlayer and Android.

My question is the way? and how can this be solved?

+5
source share
2 answers

You should look for the seekTo method. This expects miliseconds as a temporary displacement. Your offset is how far from the start you want to play, for example, 1 minute from the start can be your offset.

Note: my lines look like this: 5: 12.201 (Mins : Secs : Millisecs)

If you want to find a time like 5:12.201 , use seekTo(312201);

Clarification :

1000 ms gives you one second, so 12000 is 12 seconds, and 60,000 is one minute.

If you want 5m:12s , follow these steps:

 MyMins = 1000 * 60 * 5; //# 5 mins at 60 secs per minute MySecs = 1000 * 12; //# 12 secs MyMilliSecs = 201; //# 201 millisecs SeekValue = (MyMins + MySecs + MyMilliSecs); seekTo(SeekValue); //# seeks to 312201 millisecs (is == 5 min & 12 secs & 201 ms) 
+2
source

I usually use this feature.

I think this can help you.

  public static String milliSecondsToTimer(long milliseconds){ String finalTimerString = ""; String secondsString = ""; int hours = (int)( milliseconds / (1000*60*60)); int minutes = (int)(milliseconds % (1000*60*60)) / (1000*60); int seconds = (int) ((milliseconds % (1000*60*60)) % (1000*60) / 1000); if(hours > 0){ finalTimerString = hours + ":"; } if(seconds < 10){ secondsString = "0" + seconds; }else{ secondsString = "" + seconds;} finalTimerString = finalTimerString + minutes + ":" + secondsString; return finalTimerString; } 

Good luck :)

+1
source

All Articles