title: How to keep my audio from overlapping
body: <p>I have a simple listview with the name of some songs.  When you click on one of the childs, the song plays.  However, I noticed that when you accidentally tap it again while its playing, it start to play again causing the sounds to overlap.  How can I set it up so that when you click on one song and then click on another song, the first song stop and the second song begins.  How can I modify my code to accomplish this.  Any help would be appreciated.</p>
  
  <pre><code>                        public class TwelveGrammar extends ActionBarActivity {
  
  private ListView lv;
  private MediaPlayer mp;
  
  
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.twelve_grm);
  
  
  
      lv = (ListView) findViewById(R.id.list); 
  
      ArrayAdapter&lt;String&gt; arrayAdapter = new ArrayAdapter&lt;String&gt; (
              this, android.R.layout.simple_list_item_1, Exp_list);
  
      lv.setAdapter(arrayAdapter);
  
      lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
  
          @Override
          public void onItemClick(AdapterView&lt;?&gt; arg0, View view, int pos,
                  long id) {
  
              if (mp.isPlaying()) {
  
                  mp.stop();
  
              }
  
              else {
              if (pos==0) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1200);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
              if (pos==1) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1201);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
  
                          }
                  });
              }
  
              if (pos==2) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1202);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
              }
  
              if (pos==3) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1203);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
  
              if (pos==4) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1204);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
              }
  
              if (pos==5) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1205);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
              if (pos==6) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1206);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
              if (pos==7) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1207);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
              if (pos==8) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1208);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
              if (pos==9) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1209);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
              if (pos==10) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1210);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
              if (pos==11) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1211);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
              if (pos==12) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1212);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
  
              if (pos==13) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1213);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
                 if (pos==14) {
  
                  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1214);
                  mp.start();
                  mp.setOnCompletionListener(new OnCompletionListener() {
                      public void onCompletion(MediaPlayer mp) {
                          mp.release();
                          }
                  });
  
              }
        if (pos==15) {
  
  mp = MediaPlayer.create(getBaseContext(), R.raw.g_1215);
  mp.start();
  mp.setOnCompletionListener(new OnCompletionListener() {
      public void onCompletion(MediaPlayer mp) {
          mp.release();
          }
  });
  
          }
  </code></pre>
  
  <p>}</p>