title: Play a resource video using Android's MediaPlayer class
body: <p>I save a video, <code>test.mp4</code>, in my project's <code>res/raw</code> directory. I have my <code>SurfaceView</code> declared as such:</p>
  
  <pre><code>  &lt;SurfaceView android:id="@+id/surface"
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:layout_gravity="center"&gt;
    &lt;/SurfaceView&gt;
  </code></pre>
  
  <p>Then, in my activity's <code>onCreate ()</code> method, I have the following:</p>
  
  <pre><code>private MediaPlayer mp;
  private SurfaceView view;
  private SurfaceHolder holder;
  
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState)
  {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.main);
      view = (SurfaceView) findViewById (R.id.surface);
      holder = view.getHolder();
      holder.setKeepScreenOn (true); 
      mp = MediaPlayer.create(this.getBaseContext (), R.raw.test);
      mp.setDisplay (holder);
      mp.setLooping (true);
      mp.start();
  }
  </code></pre>
  
  <p>I don't get why it doesn't show the video, even if I set the display. I'm running on API 7 (2.1.1) and I get the audio. I need a Video-only type of interface, without the control panel. As far as I know, <code>VideoView</code>, although simpler than <code>MediaPlayer</code>, has a built-in control layer. Also, I don't see a way to use <code>VideoView</code> on a resource. If there are workarounds for these two issues I have, or if my assumption of <code>VideoView</code> is wrong, I'd appreciate being told.</p>
  
  <hr>
  
  <p><strong>UPDATE:</strong> I am currently using the <code>VideoView</code> class. My assumption really was wrong about automatically having a UI control panel. Still, I have NOT been able to play videos stored in <code>res/raw</code> via the <code>MediaPlayer</code> class; it always fails when I call <code>prepare ()</code> or the audio plays, but the video doesn't. Because of this, my question still stands. </p>
  
  <p>If anyone runs into my question about how I used VideoView, let me save you some trouble in looking for how to retrieve a video in <code>res/raw</code>. The following snippet assumes you have a <code>VideoView</code> with an id of <code>view</code> in a layout file, <code>main.xml</code>:</p>
  
  <pre><code>public class generalActivity extends Activity {
      @Override
      public void onCreate (Bundle icicle) {
          super.onCreate (icicle);
          this.setContent (R.layout.main);
  
          // You know the that view is an instance of VideoView, so cast it as such
          VideoView v = (VideoView) this.findViewById (R.id.view);
  
          // This is the name of the video WITHOUT the file extension.
          // In this example, the name of the video is 'test.mp4'
          String videoName = "test"
  
          // You build the URI to your video here
          StringBuilder uriPathBuilder = new StringBuilder ();
          uriPathBuilder.append ("android.resource://");
          uriPathBuilder.append (this.getPackageName ());
          uriPathBuilder.append (File.separator);
          uriPathBuilder.append ("raw");
          uriPathBuilder.append (File.separator);
          uriPathBuilder.append (videoName);
          Uri uri = Uri.parse (uriPathBuilder.toString ());
  
          view.setVideoURI (uri);
          view.start ();
      }
  }
  </code></pre>
  
  <p>Here's the link that I used as a reference to get the uri path: <a href="https://stackoverflow.com/questions/3448393/what-is-the-path-to-your-apps-assets-folder-in-android/3448604#3448604">reference link</a></p>
  
  <p>I'm leaving this open because I asked if I could play video in <code>res/raw</code> using MediaPlayer, and not <code>VideoView</code>. Even if I got it to work the way I wanted using <code>VideoView</code>, as far as I know, there are still things <code>MediaPlayer</code> can do that <code>VideoView</code> can't. I could be wrong though, so if you just need to show a video and don't need anything advanced, I'm pretty sure <code>VideoView</code> will suffice.</p>
  
  <p>Oh, and thanks to @Ravi for all the help.</p>