title: android - changing the file played in mediaplayer dynamically
body: <p>I'm trying to play sounds dynamically.
  I have a resource diractory that I have created under res folder that is called "raw". this diractory contains mp3 files.
  what I want to do is to make an Array with all the files names, and when a button is clicked the next mp3 int the next index will be loaded to the mediaplayer and will be playable.</p>
  
  <p>I have found this code for using mediaplayer</p>
  
  <pre><code>public class MainActivity extends ActionBarActivity {
  Context context = this;
  MediaPlayer mp;
  
  @Override
  public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main_layout);
      mp = MediaPlayer.create(context, R.raw.sound);
      final Button b = (Button) findViewById(R.id.Button);
      b.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
  
              try {
                  if (mp.isPlaying()) {
                      mp.stop();
                      mp.release();
                      mp = MediaPlayer.create(context, R.raw.sound);
                  } mp.start();
              } catch(Exception e) { e.printStackTrace(); }
          }
      });
  }
  }
  </code></pre>
  
  <p>but I can't seem to find the way to set track switching by Array with using the song name on the i index.</p>
  
  <p>Thanks for any help</p>