Play Video From Raw Folder

Posted by SterAllures on Stack Overflow See other posts from Stack Overflow or by SterAllures
Published on 2011-01-02T22:17:24Z Indexed on 2011/01/02 22:53 UTC
Read the original article Hit count: 211

Filed under:

Evening,

I've just started programming with android and made a few programs and everything so I'm still kind of a novice but im trying to understand it all.

So here's my problem, I'm trying to play a video, the thing is, I got it working when I Stream it from an URL with VideoView over the internet or when i place in on my sdcard.

What I want to do now is play a video I've got in my res/raw folder, but it only plays audio and I don't understand why, it doesn't give any error in my logcat as far as I can see, also couldn't really find a solution with google since most of the answers are about VideoView and just put the video on your SDCard.

Now someone told me I had to use setDisplay (SurfaceHolder) and I've also tried that but I still only get the audio.

I hope somebody can help me to find a solution to this problem.

VideoDemo.java

package nl.melvin.videodemo; 

import android.app.Activity; 
import android.os.Bundle; 
import android.media.MediaPlayer; 
import android.view.SurfaceHolder; 
import android.view.SurfaceView; 


public class videodemo extends Activity { 

    public SurfaceHolder holder; 
    public SurfaceView surfaceView; 


    /** Called when the activity is first created. */ 
    @Override 
    public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 


        MediaPlayer mp = MediaPlayer.create(this, R.raw.mac); 

        mp.setDisplay(holder); 
        mp.start(); 

      } 

} 

XML

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout  
    xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/LinearLayout01"  
     android:layout_width="fill_parent"  
     android:layout_height="fill_parent" > 
    <SurfaceView 
        android:id="@+id/surfaceview" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent"> 
     </SurfaceView>> 
</LinearLayout>

I've also tried Uri.parse but it says it can't play the video (.mp4 format).

© Stack Overflow or respective owner

Related posts about android