Skip to content Skip to sidebar Skip to footer

Android How To Stop Media Player When New Sound Start In Recycleview

I try to find solution but could not find it. My problem is that i have lots of items in recycleview. Each item has image and when i click that image it start sound for that image.

Solution 1:

Add this:

@OverridepublicvoidonClick(View v) {
stopPlaying();  <-------            
MediaPlayermediaPlayer=   MediaPlayer.create(v.getContext(),mItem.getmSound());
mediaPlayer.start();}

and this:

.......

publicZivotinjeAdapter(List<Zivotinje> animals) {
    mZivotinje = animals;
}

privatevoidstopPlaying() {

    if(mediaPlayer != null && mediaPlayer.isPlaying())
    {
        mediaPlayer.stop();
        mediaPlayer.reset();
        mediaPlayer.release();
        mediaPlayer = null;
    }
}

Post a Comment for "Android How To Stop Media Player When New Sound Start In Recycleview"