1

I have done a simple stopwatch app. I have start and pause button to start and stop/pause sound respectively. Right now my buttons are able to start and stop sound. But since my sound file is 2 minutes long, it only plays 2 minutes and after that stops automatically.

Now, what I want is to keep playing the sound forever until the pause button is pressed.

private MediaPlayer mp;//is originally initialized inside the class but outside method
    startButton = (Button) findViewById(R.id.startButton);

        startButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {
                startTime = SystemClock.uptimeMillis();
                customHandler.postDelayed(updateTimerThread, 0);
           mp.start();
          }
        });

        pauseButton = (Button) findViewById(R.id.pauseButton);

        pauseButton.setOnClickListener(new View.OnClickListener() {

            public void onClick(View view) {

                timeSwapBuff += timeInMilliseconds;
                customHandler.removeCallbacks(updateTimerThread);
                mp.stop();

            }
        });
Riyana
  • 241
  • 13
  • 29

2 Answers2

3
mMediaPlayer.setLooping(true);
Bhaskar
  • 911
  • 6
  • 18
2

For song looping try using mp.setLooping(true); something like this:

MediaPlayer mp; mp = MediaPlayer.create(this, R.raw.your_song); mp.setLooping(true);

ettore
  • 78
  • 1
  • 5
  • Generally avoid code-only answers. Consider adding a `description` that helps to explain your code and in this case explain where in context that code should be used. Thanks –  Mar 24 '15 at 05:57
  • Yes is true but is an exmple however i am goig to correct it for better explanation. – ettore Mar 24 '15 at 15:56