Answer the question
In order to leave comments, you need to log in
How to pause the previous media file when clicking on a new one?
I have an android application in java,
when the button is pressed, the function of playing the file in the sound is substituted for the current MediaPlayer, in the same place clearing the memory after playing onCompletion. How to do if one media file is playing, when you click on another button, the second one is played, but the first one stops.
public void soundPlay(MediaPlayer sound) {
sound.start();
sound.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();;
}
});
}
public void soundPlay(MediaPlayer sound) {
if(m != null) {
m.stop();
}
sound.start();
sound.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.release();;
}
});
m = sound;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question