广告
返回顶部
首页 > 资讯 > 移动开发 >android使用videoview播放视频
  • 646
分享到

android使用videoview播放视频

videoviewAndroid 2022-06-06 10:06:15 646人浏览 独家记忆
摘要

代码如下:public class Activity01 extends Activity{  @Override public void on

代码如下:
public class Activity01 extends Activity
{
 
 @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>

您可能感兴趣的文章:一个HTML5播放视频的video控件只支持android的默认格式mp4和3gpAndroid播放视频的三种方式android播放视频时在立体声与单声道之间切换无变化原因分析及解决Android编程实现播放视频时切换全屏并隐藏状态栏的方法Android仿新浪微博/QQ空间滑动自动播放视频功能Android编程实现播放视频的方法示例Android多媒体教程之播放视频的四种方法Android ViewPager中显示图片与播放视频的填坑记录Android DragVideo实现播放视频时任意拖拽的方法android使用surfaceview+MediaPlayer播放视频


--结束END--

本文标题: android使用videoview播放视频

本文链接: https://www.lsjlt.com/news/27166.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作