public class VideoViewTest extends Activity {
private VideoView vv;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.as);
vv = (VideoView) findViewById(R.id.video);
//设置播放视频文件的目录
vv.setVideoPath(Environment.getExternalStorageDirectory().getAbsolutePath() + "/cc.mp4");
//使用默认的视频控制器
vv.setMediaController(new MediaController(this));
//开始播放视频
vv.start();
}
}
XML文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:onClick="download"
/>
<VideoView
android:id="@+id/video"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>