title: How to create MediaPlayer from string in android studio
body: <p>I'm currently trying to make an app that plays a sound, and worked using:</p>
  <pre><code>soundPlayer = MediaPlayer.create(this, R.raw.audio1);
  soundPlayer.start();
  </code></pre>
  <p><code>audio1.mp3</code> is in the <code>\res\raw</code> resource.
  Now I'm trying to do the same but instead of using <code>R.raw</code>, I want to get the file from a string that contains the file name.</p>
  <p>I tried this code that i found in another similar question in here but the id is ALWAYS zero:</p>
  <pre><code>public void playSound(String audioToPlay){
      int sound_id = getApplicationContext().getResources().getIdentifier(&quot;audio1.mp3&quot;, &quot;raw&quot;, getApplicationContext().getPackageName());
      if (sound_id != 0) {
          soundPlayer = MediaPlayer.create(this, sound_id);
          soundPlayer.start(); 
      }
  </code></pre>