Android: Embed mp4 Video from Raw

Put the video inside the res/raw

embed-mp4-video-in-raw-android

 

Layout - vidconsult.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

<VideoView android:id="@+id/vidview"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</VideoView>
</LinearLayout>


The sourcecode: playvid.java
import android.app.Activity;
import android.net.Uri;
import android.os.Bundle;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;

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

VideoView myVideoView = (VideoView) findViewById(R.id.vidview);
MediaController mediaController = new MediaController(this);
mediaController.setAnchorView(myVideoView);
try{//try to fetch vid from sdcard
//String SrcPath = "/sdcard/week17boy.avi";//put your video in sdcard
String vidpath = "android.resource://" + getPackageName() + "/" + R.raw.rsr;
myVideoView.setVideoURI(Uri.parse(vidpath));
//myVideoView.setVideoPath(SrcPath);
myVideoView.setMediaController(new MediaController(this));
myVideoView.requestFocus();
myVideoView.start();
}
catch (Exception e){
Toast.makeText(getApplicationContext(), e.toString(), Toast.LENGTH_SHORT);
}

}
}


 


embed-mp4-video-in-raw-android

6 comments:

  1. I had copy all ur code an run it... but it show cnt play video...

    ReplyDelete
    Replies
    1. The fact that the emulator could not play the video really well. You need to test the video playback using actual device...

      Delete
  2. it worked but i cannot see the video .. just the music

    ReplyDelete
  3. i cannot see the video in emulator .. just the music

    ReplyDelete
    Replies
    1. The fact that the emulator could not play the video really well. You need to test the video playback using actual device...

      Delete

Popular Posts