title: Android how to stop media player when new sound start in Recycleview
body: <p>I try to find solution but could not find it.</p>
  
  <p>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.
  Problem is when i start new sound previous sound do not stop, its keep playing until sound finish. After i click 15, 20 sounds app get crashed and i receive this error message: </p>
  
  <p>E/MediaPlayer: error (1, -19)</p>
  
  <p>Somehow i need to implement release and stop of the previous sound when i click on the new one. I try to find solution but i could not find it for recycleview.</p>
  
  <p>Here is my Adapter code:</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import android.content.Context;
  import android.media.MediaPlayer;
  import android.support.v7.widget.RecyclerView;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.ImageView;
  import android.widget.TextView;
  
  import com.bumptech.glide.Glide;
  
  import java.util.List;
  
  
  public class ZivotinjeAdapter extends RecyclerView.Adapter&lt;ZivotinjeAdapter.ViewHolder&gt; {
  
      @Override
      public ZivotinjeAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
          Context context = parent.getContext();
          LayoutInflater inflater = LayoutInflater.from(context);
  
          // Inflate the custom layout
          View contactView = inflater.inflate(R.layout.item_zivotinje, parent, false);
  
          // Return a new holder instance
          ViewHolder viewHolder = new ViewHolder(contactView);
          return viewHolder;
      }
  
      @Override
      public void onBindViewHolder(ZivotinjeAdapter.ViewHolder viewHolder, int position) {
  
  
          Zivotinje zivotinjeIme = mZivotinje.get(position);
  
          // Set item views based on the data model
          TextView textView = viewHolder.nameTextView;
          textView.setText(zivotinjeIme.getmAnimal_name());
  
          //THIS IS WHERE I HANDALE IMAGE VIEW. Using glide for images
          ImageView slika_source = viewHolder.imageView;
          Glide.with(slika_source.getContext())
                  .load((Integer) zivotinjeIme.getmAnimal_slika())
                  .into(slika_source);
  
  
  
          viewHolder.setItem(mZivotinje.get(position));
  
      }
  
  
      @Override
      public int getItemCount() {
          return mZivotinje.size();
      }
  
      public static class ViewHolder extends RecyclerView.ViewHolder {
  
          public ImageView imageView;
          public TextView nameTextView;
          private Zivotinje mItem;
  
  
  
          public void setItem(Zivotinje item) {
              this.mItem = item;
          }
  
  
  
          public ViewHolder(final View itemView) {
              super(itemView);
  
              nameTextView = (TextView) itemView.findViewById(R.id.zivotinjaIme_id);
              imageView = (ImageView) itemView.findViewById(R.id.slika_id);
  
              
  //this is click event for each item and here i play sound
              itemView.setOnClickListener(new View.OnClickListener() {
                  @Override
                  public void onClick(View v) {
                      
                      MediaPlayer mediaPlayer = MediaPlayer.create(v.getContext(), mItem.getmSound());
                      mediaPlayer.start();
  
                  }
              });
  
          }
  
  
      }
  
      private List&lt;Zivotinje&gt; mZivotinje;
  
      public ZivotinjeAdapter(List&lt;Zivotinje&gt; animals) {
          mZivotinje = animals;
      }
  
  
  
  
  }</code></pre>
  </div>
  </div>
  </p>