Search code examples
javaandroidmp3android-mediaplayer

play mp3 files at designated duration


I'm trying to make an app that can play mp3 files at designated duration through MediaPlayer

for example:

Start Time: 00:42

End Time: 01:23

my question is:

-is it possible to designate the start and end time via textview at MM:SS format?

Thanks!!


Solution

  • Yes after initiating the MediaPlayer and loading the file , you can pause or stop the player after using specific time

    while(mPlayer.isPlaying()) {
              if(mPlayer.getCurrentPosition() > 7254 && mPlayer.getCurrentPosition() < 7410 ){ 
                  labelTxt.setText("Stop: " + mPlayer.getCurrentPosition() );
                  mPlayer.stop();
                  break;
              }
            }