【安卓】VideoView播放本地视频

版权声明:我是Extends-- https://blog.csdn.net/qq_25955641/article/details/88204837

首先布局文件里加入VideoView

然后将视频放在res/raw目录下,没有的话就新建一个

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#f1f1f1"
    android:orientation="vertical" >

    <VideoView
        android:id="@+id/videoView"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
</LinearLayout>
播放效果

img1

 

第一步: 建立媒体管理器

MediaController controller = new MediaController(getContext());

第二步:设置播放地址

 videoView.setVideoURI(
                Uri.parse("android.resource://" +
                        getContext().getPackageName() + "/raw/" +
                        R.raw.car1));
        

第三步:设置媒体管理器

videoView.setMediaController(controller);

第四步:获取焦点并开始播放视频

videoView.requestFocus();
videoView.start();

 

 

 

猜你喜欢

转载自blog.csdn.net/qq_25955641/article/details/88204837
今日推荐