android使用videoview播放视频
public class activity01 extends activity
{
/** called when the activity is first created. */
@override
public void oncreate(bundle savedinstancestate)
{
super.oncreate(savedinstancestate);
setcontentview(r.layout.main);
final videoview videoview = (videoview) findviewbyid(r.id.videoview01);
button pausebutton = (button) this.findviewbyid(r.id.pausebutton);
button loadbutton = (button) this.findviewbyid(r.id.loadbutton);
button playbutton = (button) this.findviewbyid(r.id.playbutton);
// load
loadbutton.setonclicklistener(new onclicklistener() {
public void onclick(view arg0)
{
// videoview.setvideopath("/sdcard/test.mp4");
videoview.setvideopath("android.resource://com.homer/"+r.raw.china);
videoview.setmediacontroller(new mediacontroller(activity01.this));
videoview.requestfocus();
}
});
// play
playbutton.setonclicklistener(new onclicklistener() {
public void onclick(view arg0)
{
videoview.start();
}
});
// pause
pausebutton.setonclicklistener(new onclicklistener() {
public void onclick(view arg0)
{
videoview.pause();
}
});
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<absolutelayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<textview
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<videoview
android:id="@+id/videoview01"
android:layout_width="320px"
android:layout_height="240px" />
<button
android:id="@+id/loadbutton"
android:layout_width="80px"
android:layout_height="wrap_content"
android:layout_x="30px"
android:layout_y="300px"
android:text="装载" />
<button
android:id="@+id/playbutton"
android:layout_width="80px"
android:layout_height="wrap_content"
android:layout_x="120px"
android:layout_y="300px"
android:text="播放" />
<button
android:id="@+id/pausebutton"
android:layout_width="80px"
android:layout_height="wrap_content"
android:layout_x="210px"
android:layout_y="300px"
android:text="暂停" />
</absolutelayout>
上一篇: android读取短信示例分享
下一篇: Android实现粒子爆炸效果的方法