Search code examples
androidandroid-mediaplayer

How to jump 10minute forward in audio when click on next button?


I have tried some logics but not getting any success. I am working on a Audio player application. And I am using MediaPlayer class to play audio files from sdcard. Now let me explain situation where I am facing issue.

Situation:

There is a 60min audio file. Now I want to implement functionality like when click on NEXT Button audio should jump 10min forward. And if i click on PREVIOUS Button audio should jump 10min backward. For example, right now if my audio is on 5min and I click on next button audio should jump on 15 min.


Solution

  • Hello friends i got the answer i am posting it here so it can be useful for others...it is simple logic

    private int TIME_INTERVAL = 60000;
    private MediaPlayer mp;
    

    In onCreate method just initialise media player object

    mp = MediaPlayer.create(this, R.raw.music);
    

    //On next button click 1minute jump from current position

    case R.id.imageNext:
                    int currentDuration = mp.getCurrentPosition();
                    mp.seekTo(currentDuration + TIME_INTERVAL);
                    break;
                case R.id.imagePrevious:
                    int currentDuration1 = mp.getCurrentPosition();
                    mp.seekTo(currentDuration1 - TIME_INTERVAL);
     private int TIME_INTERVAL = 60000;