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

Popular Posts

WorldConferences.net