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. AudioManager的简单使用
  2. Android—常用控件(四)日期/时间控件
  3. Android(安卓)实现控件浮动效果
  4. Android(安卓)左右滑动控件
  5. android里的ViewGroup
  6. android EditText 控件中加入图片(非背景图片)
  7. Android中在OnCreate时获得控件高度
  8. Android中判断是否有声音在播放
  9. android中MotionEvent.ACTION_CANCEL事件如何被触发?

随机推荐

  1. Android 系统framework 概述
  2. Android上的Notification
  3. Logger详解(一)
  4. Android Studio镜像设置
  5. 【android】android短信数据库表
  6. Android快速集成框架:MVP+Dagger+主流框架
  7. Android创建桌面快捷方式
  8. Android软件开发常用系统控件(一) TextView
  9. 第十四周实验报告:实验四 Android程序设计
  10. listview android:cacheColorHint,listSe