VideoView实现全屏和横屏播放

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/memgxingfeixiang/article/details/52702907

1)XML布局

         <VideoView>控件的使用:

在布局的时候,VideoView要使用一个控件包裹起来,我这里使用的是id= Video_play_quanRelativeLayout控件。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
   
xmlns:tools="http://schemas.android.com/tools"
   
android:layout_width="match_parent"
   
android:layout_height="match_parent"
>
   
    <RelativeLayout
       
android:id="@+id/Video_play_quan"
       
android:layout_width="match_parent"
       
android:layout_height="match_parent"
>

    <VideoView
       
android:id="@+id/videoView"
       
android:layout_width="match_parent"
       
android:layout_height="match_parent"
/>

    </RelativeLayout>

</RelativeLayout>

2)java代码实现

   public void playVideo(String path){
//     String path =Environment.getExternalStorageDirectory().getPath() + File.separator +"test.mp4";
       
videoView.setVideoURI(Uri.parse(path));

        MediaController mctrl = new MediaController(this);
        videoView.setMediaController(mctrl);

        RelativeLayout.LayoutParamslayoutParams = new RelativeLayout.LayoutParams(
               RelativeLayout.LayoutParams.FILL_PARENT,
               RelativeLayout.LayoutParams.FILL_PARENT);
        layoutParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
       layoutParams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
       layoutParams.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
       layoutParams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        videoView.setLayoutParams(layoutParams);

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

展开阅读全文

没有更多推荐了,返回首页