Search code examples
androidmedia-player

Android SDK - how to stop all mediaplayer at once


I made a soundboard, and the code creates a mediaplayer for every item when clicked. Here's my code:

public void onListItemClick(ListView parent, View v, int position, long id){

Sound s = (Sound) mSounds.get(position);

MediaPlayer mp = MediaPlayer.create(this, s.getSoundResourceId());

mp.start();

}

But I want to create a button to stop all sounds that are playing. Is there any way to stop ALL mediaplayer objects ?


Solution

  • Why not put all MediaPlayers in a Collection?

    Then you can just iterate over the collection and stop them.