安卓videoView 横屏,全屏显示

 

videoView的原码中对videoView播放的视频做了一定的处理导致视频不能按你以为的形式呈现在videoView中。

首先重写VideoView

   <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <com.sxy.view.CustomVideoView
                android:id="@+id/videoView"
                android:layout_width="match_parent"
                android:layout_height="230dip" />
        </RelativeLayout>

public class CustomVideoView extends VideoView {

 private int mVideoWidth;
 private int mVideoHeight;

 public CustomVideoView(Context context) {
  super(context);
  // TODO Auto-generated constructor stub
 }

 public CustomVideoView(Context context, AttributeSet attrs) {
  super(context, attrs);
  // TODO Auto-generated constructor stub
 
 }

 public CustomVideoView(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);
  // TODO Auto-generated constructor stub
 }

 @Override
 public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
  
  int width = getDefaultSize(mVideoWidth, widthMeasureSpec);
  int height = getDefaultSize(mVideoHeight, heightMeasureSpec);
  setMeasuredDimension(width, height);
 }
}

其实就是屏蔽掉了系统的VideoView的一些控制方法,让视频的播放的长宽是根据你设置的参数来决定

 然后,控制点击方法来实现横竖屏

对控制全屏的按钮事件添加如下代码: 

getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);//设置videoView全屏播放
     setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置videoView横屏播放

    //获取屏幕的宽高 height_01 ,width_01
     WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
     android.view.Display display = wm.getDefaultDisplay();
     int height_01 = display.getHeight();
     int width_01 = display.getWidth();

     //我布局中videoView的父控件是RelativeLayout所以使用RelativeLayout.LayoutParams
     RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) videoView
       .getLayoutParams(); // 取控当前的布局参数
     layoutParams.height = height_01;//设置 当控件的高强
     layoutParams.width = width_01;  
     videoView.setLayoutParams(layoutParams); // 使设置好的布局参数应用到控件

好了视频的横屏播放就完成了,棒棒哒!

 

  • 5
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

xiaoqiang_0719

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值