0

i'm following a step to play audio file from here link

and it works all right, the service in the link above is to play and stop audio. The problem is i want to change a button background when the audio stop, so far i only got this in the activity that call the service:

btnPlay.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (isPlaying == false) {
                isPlaying = true;
                btnPlay.setBackgroundResource(R.drawable.stop_play_button);
                playAudio();
            } else {
                isPlaying = false;
                btnPlay.setBackgroundResource(R.drawable.play_button);
                stopAudio();
            }
        }
    });
Idham Choudry
  • 589
  • 10
  • 31
  • You need to implement binder interface, more on this here http://stackoverflow.com/questions/23586031/calling-activity-class-method-from-service-class – satorikomeiji Apr 16 '16 at 14:45

1 Answers1

1

You can declare on completetion listener on your player:

player.setOnCompletionListener(new OnCompletionListener() {
        @Override
        public void onCompletion(MediaPlayer mp) {
            isPlaying = false;
            btnPlay.setBackgroundResource(R.drawable.play_button);
            stopAudio();
           }
        });
motis10
  • 2,484
  • 1
  • 22
  • 46