AndroidVideoPlayer在線播放視頻,自定義SuperVideoPlayer裡面封裝了startPlayVideo()播放視頻
loadAndPlay(String videoUrl, int seekTime)加載並開始播放視頻,loadVideo(String videoUrl) 加載視頻,
playVideoAtLastPos()更換清晰度地址時,loadMultipleVideo(ArrayList<Video> allVideo) 播放多個視頻,等方法
本項目來源:https://github.com/xiongwei-git/AndroidVideoPlayer
本項目主要代碼:
據屏幕方向重新設置播放器的大小
/***
* 旋轉屏幕之後回調
* @param newConfig
*/
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(null == mSuperVideoPlayer)return;
/***
* 根據屏幕方向重新設置播放器的大小
*/
if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().getDecorView().invalidate();
float height = DensityUtil.getWidthInPx(this);
float width = DensityUtil.getHeightInPx(this);
mSuperVideoPlayer.getLayoutParams().height = (int)width;
mSuperVideoPlayer.getLayoutParams().width = (int)height;
} else if (this.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
final WindowManager.LayoutParams attrs = getWindow().getAttributes();
attrs.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(attrs);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
float width = DensityUtil.getWidthInPx(this);
float height = DensityUtil.dip2px(this, 230.f);
mSuperVideoPlayer.getLayoutParams().height = (int)height;
mSuperVideoPlayer.getLayoutParams().width = (int)width;
}
}
/***
* 恢復屏幕至豎屏
*/
private void resetPageToPortrait(){
if (getRequestedOrientation() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mSuperVideoPlayer.setPageType(MediaController.PageType.SHRINK);
}
}