1 XML file name: Videoplayer
Main activity naming: videoactivity
Put the video file on the phone sdcard/ceshi.3gp note the video name and format
<?xml version= "1.0" encoding= "Utf-8"?>
<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
androidrientation= "Vertical"
Android:layout_width= "Fill_parent"
android:layout_height= "Fill_parent" >
<textview
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "@string/hello"
/>
<videoview
Android:id= "@+id/video_view"
Android:layout_width= "Fill_parent"
android:layout_height= "300px"
/>
<button android:id= "@+id/cmd_load"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "Load"
/>
<button android:id= "@+id/cmd_play"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Android:text= "This is a video"
/>
<button android:id= "@+id/cmd_pause"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
android:text= "Pause"
/>
</LinearLayout>
2, Java code package com.eoeandroid.demo.VideoPlayer;
Import android.app.Activity;
Import Android.os.Bundle;
Import Android.util.Log;
Import Android.view.View;
Import Android.view.View.OnClickListener;
Import Android.widget.Button;
Import Android.widget.VideoView;
public class Videoactivity extends Activity {
private static final String TAG = "videoactivity";
public void OnCreate (Bundle icicle) {
Super.oncreate (Icicle);
Settitle ("videoactivity");
LOG.V (TAG, "onCreate: ===>");
Setcontentview (R.layout.videoplayer);
Final Videoview view = (videoview) Findviewbyid (R.id.video_view);
Button Cmdload = (button) This.findviewbyid (r.id.cmd_load);
Cmdload.setonclicklistener (New Onclicklistener () {
public void OnClick (View arg0) {
TODO auto-generated Method Stub
LOG.V (TAG, "Setvideopath: ===>");
View.setvideopath ("/sdcard/ceshiu.3gp");
}
});
Button Cmdplay = (button) This.findviewbyid (R.id.cmd_play);
Cmdplay.setonclicklistener (New Onclicklistener () {
public void OnClick (View arg0) {
TODO auto-generated Method Stub
LOG.V (TAG, "Start: ===>");
View.start ();
}
});
Button Cmdpause = (button) This.findviewbyid (R.id.cmd_pause);
Cmdpause.setonclicklistener (New Onclicklistener () {
public void OnClick (View arg0) {
TODO auto-generated Method Stub
LOG.V (TAG, "pause: ===>");
View.pause ();
}
});
}
}
Copy the code is also relatively simple that, get videoview, and then use a few buttons to demonstrate the load video and play, pause action.
It is important to note that:
The video file at the end is not too big, I used a 6M, loaded up can also.
Finally, the video file is put on the SD card, do not pack together.
On this basis, you can add some control buttons such as fast forward and rewind.
Example of playing video in Android