title: Android MediaPlayer: Play Audio Resource in Raw Based on URI
body: <p>The problem I am trying to solve is in an activity that needs to play back audio files.  Most of the files will be user created (and saved into external storage), and therefore played with the following code (based on Google's example code):</p>
  
  <pre><code>MediaPlayer mPlayer = new MediaPlayer();
  mPlayer.setDataSource(filename);
  mPlayer.prepare();
  mPlayer.start();
  </code></pre>
  
  <p>Some of the audio files, though, are going to be included with the app, are usually played with the following code:</p>
  
  <pre><code>MediaPlayer mPlayer = MediaPlayer.create(getBaseContext(), R.raw.filename);
  mPlayer.prepare();
  mPlayer.start();
  </code></pre>
  
  <p>The issue is that I would like to be able to play the audio files in the raw folder in the same way that I am playing the user created files since I don't necessarily know which will be needed.  I tried tried to get the URI of the audio file in the raw folder and play it with the following code:</p>
  
  <pre><code>Uri uri = Uri.parse("android/resource://com.my.package/" + R.raw.filename);
  MediaPlayer mPlayer = new MediaPlayer();
  mPlayer.setDataSource(uri.toString());
  mPlayer.prepare();
  mPlayer.start();
  </code></pre>
  
  <p>But nothing happens.  No error messages, no playing audio.</p>
  
  <p>I outlined what I thought was the simplest solution, but I am willing to go another route if it accomplishes the task.  Any assistance is greatly appreciated.</p>