android使用videoview播放视频

 更新时间:2014年02月28日 16:46:39   作者:  
这篇文章主要介绍了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自定义属性 format的深入解析

    Android自定义属性 format的深入解析

    以下是对Android中的自定义属性format进行了详细的分析介绍,需要的朋友可以过来参考下
    2013-07-07
  • Android UI控件之ProgressBar进度条

    Android UI控件之ProgressBar进度条

    这篇文章主要为大家详细介绍了Android UI控件之ProgressBar进度条的实现代码,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-12-12
  • Android如何监测文件夹内容变化详解

    Android如何监测文件夹内容变化详解

    最近在开发android应用程序的时候遇到了一个监测文件夹的功能,所以下面这篇文章主要给大家介绍了关于Android如何监测文件夹内容变化的相关资料,需要的朋友可以参考下
    2021-12-12
  • Android Hilt依赖注入的使用讲解

    Android Hilt依赖注入的使用讲解

    这篇文章主要介绍了Android Hilt依赖注入的使用,首先,某个类的成员变量称为依赖,如若此变量想要实例化引用其类的方法,可以通过构造函数传参或者通过某个方法获取对象,此等通过外部方法获取对象实例的称为依赖注入
    2023-01-01
  • Android Shader应用开发之雷达扫描效果

    Android Shader应用开发之雷达扫描效果

    这篇文章主要为大家详细介绍了Android Shader应用开发之雷达扫描效果,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2017-07-07
  • Android列表控件Spinner简单用法示例

    Android列表控件Spinner简单用法示例

    这篇文章主要介绍了Android列表控件Spinner简单用法,结合实例形式分析了Android列表控件Spinner的布局与功能实现技巧,需要的朋友可以参考下
    2017-12-12
  • Android 8.0系统中通知栏的适配详解

    Android 8.0系统中通知栏的适配详解

    本片文章给大家通过实例讲解分析了Android 8.0系统中通知栏的相关知识点,对此有需要的朋友可以参考学习下。
    2018-04-04
  • 详解Android用Shape制作单边框图的两种思路和坑

    详解Android用Shape制作单边框图的两种思路和坑

    这篇文章主要介绍了详解Android用Shape制作单边框图的两种思路和坑,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-08-08
  • android屏蔽按钮连续点击的示例代码

    android屏蔽按钮连续点击的示例代码

    这篇文章主要介绍了android屏蔽按钮连续点击的示例代码,本文给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-12-12
  • Android自定义TipView仿QQ长按后的提示窗口

    Android自定义TipView仿QQ长按后的提示窗口

    这篇文章主要介绍了Android自定义TipView仿QQ长按后的提示窗口,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2018-05-05

最新评论