title: Android media player not working as expected
body: <p>I am very new to android just started with Android currently referring the below code from past 2 days, not able to fix the issue.  </p>
  
  <p>Code: 
  <a href="https://github.com/quocnguyenvan/media-player-demo" rel="nofollow noreferrer">https://github.com/quocnguyenvan/media-player-demo</a></p>
  
  <p>Issue: Let's say we 4 Songs in the ListView when we click on the first song play it for some time and pause it without clicking on stop.
  As soon as we click on the second song the first song starts playing we cannot play the second song unless we click on stop of the first song How to solve this issue.</p>
  
  <p>The issue with code not able to figure out and fix it.I have referred many posts before posting on StackOverflow but could not make it, any suggestion or guidance is highly appreciated.</p>
  
  <p><strong>Problematic code:</strong> </p>
  
  <pre><code>// play music
      viewHolder.ivPlay.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if(flag){
                  mediaPlayer = MediaPlayer.create(context, music.getSong());
                  flag = false;
              }
              if(mediaPlayer.isPlaying()) {
                  mediaPlayer.pause();
                  viewHolder.ivPlay.setImageResource(R.drawable.ic_play);
              } else {
                  mediaPlayer.start();
                  viewHolder.ivPlay.setImageResource(R.drawable.ic_pause);
              }
          }
      });
  
      // stop
      viewHolder.ivStop.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if(!flag) {
                  mediaPlayer.stop();
                  mediaPlayer.release();
                  flag = true;
              }
              viewHolder.ivPlay.setImageResource(R.drawable.ic_play);
          }
      });
  </code></pre>