android使用videoview播放视频

作者:

这篇文章主要介绍了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自定义实现日历控件
    2021-11-11
  • Android CameraX结合LibYUV和GPUImage自定义相机滤镜
    Android CameraX结合LibYUV和GPUImage自定义相机滤镜
    2021-12-12
  • Android SeekBar 自定义thumb旋转动画效果
    Android SeekBar 自定义thumb旋转动画效果
    2021-11-11
  • Android服务Service教程
    Android服务Service教程
    2021-11-11
  • 通俗易通讲解Android蓝牙键值适配
    通俗易通讲解Android蓝牙键值适配
    2021-11-11
  • Windows下Flutter+Idea环境搭建及配置
    Windows下Flutter+Idea环境搭建及配置
    2021-11-11
  • 图文详解Flutter单例的实现
    图文详解Flutter单例的实现
    2021-11-11
  • Android CameraX结合LibYUV和GPUImage自定义相机滤镜
    Android CameraX结合LibYUV和GPUImage自
    2021-11-11
  • 美国设下计谋,用娘炮文化重塑日本,已影响至中国
    美国设下计谋,用娘炮文化重塑日本,已影响至中国
    2021-11-19
  • 时空伴随者是什么意思?时空伴随者介绍
    时空伴随者是什么意思?时空伴随者介绍
    2021-11-09
  • 工信部称网盘企业免费用户最低速率应满足基本下载需求,天翼云盘回应:坚决支持,始终
    工信部称网盘企业免费用户最低速率应满足基本下载需求,天翼云盘回应:坚决支持,始终
    2021-11-05
  • 2022年放假安排出炉:五一连休5天 2022年所有节日一览表
    2022年放假安排出炉:五一连休5天 2022年所有节日一览表
    2021-10-26
  • 电脑版 - 返回首页

    2006-2023 脚本之家 JB51.Net , All Rights Reserved.
    苏ICP备14036222号