参考文献
https://github.com/yaochangliang159/Vitamio-FullScreen-Demo
1.首先是导入vitamio包,网上很多教程此处不多说,建议vitamio用新版本
记得开网络权限
2.在你的项目中引入
3.修改vitamio布局文件,按自己方式增加
4.修改mediacontroller方法
隐藏掉
5.增加点击控制器
public void setOnControllerClick(OnControllerClick l){
mListener=l;
}
public interface OnControllerClick{
void OnClick(int type);
}
6重写控制器方法
public MediaController(Context context,boolean fromXml,View container) {
super(context);
initController(context);
mFromXml = fromXml;
mRoot = makeControllerView();
把MediaController的视图作为childView加到一个FrameLayout中去
FrameLayout.LayoutParams p = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
p.gravity = Gravity.BOTTOM;
mRoot.setLayoutParams(p);
((FrameLayout)container).addView(mRoot);
}
7、设置横竖屏监听
mPlayLandscape= (ImageView) v.findViewById(getResources().getIdentifier(“mediacontroller_play_landscape”, “id”, mContext.getPackageName()));
mPlayLandscape.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
mListener.OnClick(0);
}
});
8.在Activity中实现横竖屏切换
MediaController mc = new MediaController(this, true, fl_controller);
mc.setOnControllerClick(new MediaController.OnControllerClick() {
@Override
public void OnClick(int type) {
//type 0 全屏。type1 分享
if (type == 0) {
if (isPortrait) {
LinearLayout.LayoutParams fl_lp = new LinearLayout.LayoutParams(
getHeightPixel(TestActivity.this),
getWidthPixel(TestActivity.this) - getStatusBarHeight(TestActivity.this)
);
fl_controller.setLayoutParams(fl_lp);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
mVideoView.setVideoLayout(VideoView.VIDEO_LAYOUT_SCALE, 0);
isPortrait = false;
} else {
LinearLayout.LayoutParams fl_lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
DensityUtil.dip2px(200,TestActivity.this)
);
fl_controller.setLayoutParams(fl_lp);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
isPortrait = true;
}
}
}
});