Open top menu



you have to get mp3 audio file duration in android .


  •   mp.getDuration(); the method get the total mp3 audio song duration in milliseconds.
  • mp..getCurrentPosition();  the method get current positions of the mp3 song .


 private static int finalTimenin = 0;
private static int  CurrentTime = 0;
 private MediaPlayer mp;

//get the total duration 

mp = MediaPlayer.create(MainActivity.this, R.raw.cosnin);
mp.start();
finalTimenin = mp.getDuration()
Toast.makeText(getApplication(),String.valueOf(finalTimefif), Toast.LENGTH_LONG).show();

//get the current position duration 
mp = MediaPlayer.create(MainActivity.this, R.raw.cosnin);
mp.start();
CurrentTime =mp.getCurrentPosition();
Toast.makeText(getApplication(),String.valueOf(CurrentTime), Toast.LENGTH_LONG).show();

Tagged

0 comments