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


Activity

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>
运行效果:


源码下载




java教程网 www.itchm.com





更多相关文章

  1. android 动画自动播放
  2. android gif播放
  3. Android搜索框自动提示文本框——(单一提示)
  4. Android(安卓)ListView 控件学习
  5. drawable animation 循环播放
  6. ScrollView里面放入多个子控件
  7. Android中ProgressBar用法简单实例
  8. android 各种常用,不易记的dialog,等控件整理
  9. Android(安卓)的布局

随机推荐

  1. Android的OkHttp包中的HTTP拦截器Interce
  2. Using WebViews and JavaScript
  3. 【转】Android --权限大全
  4. Android之离线词典
  5. android 模拟器使用指导
  6. Android SDK Manager安装过程
  7. Android SDK 源码
  8. Android(安卓)String format
  9. Android_Servcie_后台服务总结笔记
  10. 设置listview中的item的颜色