zoukankan      html  css  js  c++  java
  • 9.1.3 使用VideoView播放

        VideoView是一个带有视频播放功能的视图,可直接在一个布局中使用,因此使用起来非常简单。

        下面是布局XML文件viewthevideo.xml,其在LinearLayout中指定了一个VedioView。

     1 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
     2     android:layout_width="match_parent"
     3     android:layout_height="match_parent"
     4     android:orientation="vertical"
     5     >
     6  <VedioView 
     7      android:layout_width="wrap_content"
     8      android:layout_height="wrap_content"
     9      android:id="@+id/VedioView"
    10   />
    11 </LinearLayout>

        为了利用这个VedioView,只须以正常的方式——传入ID(R.id.VedioView)以调用findViewById——获得它的引用。一旦获得了该对象,就可以利用setVideoURI来设置视频文件的URI,然后调用start方法类播放。

    package com.nthm.androidtestActivity;
    
    import com.nthm.androidtest.R;
    import android.app.Activity;
    import android.net.Uri;
    import android.os.Bundle;
    import android.os.Environment;
    import android.widget.VideoView;
    
    public class ViewTheVideo extends Activity {
        private VideoView vv;
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.viewthevideo);
            vv=(VideoView) findViewById(R.id.VedioView);
            Uri data=Uri.parse(Environment.getExternalStorageDirectory().getPath()+"test.mp4");
            vv.setVideoURI(data);
            vv.start();
        }
    }
  • 相关阅读:
    Python Web学习笔记之Python多线程基础
    Python入门之python可变对象与不可变对象
    Python Web学习笔记之SOCK_STREAM和SOCK_DGRAM
    background和background-position相关笔记
    自定义switch开关
    获取浏览器类型和版本号
    随机生成字符串
    white-space详解
    文件选择按钮随笔
    mouse的各种事件
  • 原文地址:https://www.cnblogs.com/ZSS-Android/p/3953221.html
Copyright © 2011-2022 走看看