Android 利用自带VideoView控件播放视频


Activity

public class Activity01 extends Activity{/** Called when the activity is first created. */@Overridepublic 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);// loadLoadButton.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();}});// playPlayButton.setOnClickListener(new OnClickListener() {public void onClick(View arg0){videoView.start();}});// pausePauseButton.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>

运行效果:



源码下载




更多相关文章

  1. 控件——SeekBar
  2. Android中android:visibility的3中属性的剖析
  3. Android的相对布局属性的解释
  4. Android中RelativeLayout各个属性的含义
  5. Android(安卓)editText(文本框) 的基本属性及用法:
  6. Android学习之 UI效果
  7. 相对布局RelativeLayout的妙用:提示标签在输入框内
  8. 【Android开发学习27】界面控件之进度条(ProgressBar)
  9. android EditText 全面阐述

随机推荐

  1. 运用开源 achartengine 绘制android端的
  2. Android(安卓)Canvas drawArc方法介绍
  3. android 程序运行出现错误 Unable to exe
  4. Android之PreferenceActivity
  5. android小注意
  6. 学习打卡 1-26
  7. Android学习之Service
  8. android 引导界面的实现
  9. python服务程序(调用摄像头查看视频和识别
  10. unity3d在android上播放视频及remote的使