效果圖

demo已上傳到coding,歡迎clone,https://e.coding.net/zhangjinhome/demo/GsyVideoPlayerDemo.git
-
匯入gsy庫:
github倉庫地址:https://github.com/CarGuo/GSYVideoPlayer
增加jitpack和阿里云代理地址:
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
maven { url "https://maven.aliyun.com/repository/public" }
}
}
添加gsy依賴:
implementation 'com.github.CarGuo.GSYVideoPlayer:GSYVideoPlayer:v8.1.7-release-jitpack'
-
輔助操作
- minSdk調至19:
minSdkVersion 19- 添加網路權限:
<uses-permission android:name="android.permission.INTERNET" />- 添加multidex(詳見Demo原始碼)
- 設定橫屏
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode" android:screenOrientation="landscape"
-
引入并使用
布局代碼:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/activity_play"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000">
<com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
android:id="@+id/video_player"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true" />
</RelativeLayout>
MainActivity.java代碼:
public class MainActivity extends AppCompatActivity {
StandardGSYVideoPlayer videoPlayer;
OrientationUtils orientationUtils;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (getActionBar() != null) {
getActionBar().hide();
}
if (getSupportActionBar() != null) {
getSupportActionBar().hide();
}
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
init();
}
private void init() {
videoPlayer = (StandardGSYVideoPlayer)findViewById(R.id.video_player);
String source1 = "http://9890.vod.myqcloud.com/9890_4e292f9a3dd011e6b4078980237cc3d3.f20.mp4";
videoPlayer.setUp(source1, true, "測驗視頻");
//增加封面
// ImageView imageView = new ImageView(this);
// imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
// imageView.setImageResource(R.mipmap.xxx1);
// videoPlayer.setThumbImageView(imageView);
//增加title
videoPlayer.getTitleTextView().setVisibility(View.VISIBLE);
//設定回傳鍵
videoPlayer.getBackButton().setVisibility(View.VISIBLE);
//設定旋轉
orientationUtils = new OrientationUtils(this, videoPlayer);
//設定全屏按鍵功能,這是使用的是選擇螢屏,而不是全屏
videoPlayer.getFullscreenButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// ------- !!!如果不需要旋轉螢屏,可以不呼叫!!!-------
// 不需要螢屏旋轉,還需要設定 setNeedOrientationUtils(false)
//orientationUtils.resolveByClick();
finish();
}
});
//是否可以滑動調整
videoPlayer.setIsTouchWiget(true);
//設定回傳按鍵功能
videoPlayer.getBackButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onBackPressed();
}
});
///不需要螢屏旋轉
videoPlayer.setNeedOrientationUtils(false);
videoPlayer.startPlayLogic();
}
@Override
protected void onPause() {
super.onPause();
videoPlayer.onVideoPause();
}
@Override
protected void onResume() {
super.onResume();
videoPlayer.onVideoResume();
}
@Override
protected void onDestroy() {
super.onDestroy();
GSYVideoManager.releaseAllVideos();
if (orientationUtils != null)
orientationUtils.releaseListener();
}
@Override
public void onBackPressed() {
/// 不需要回歸豎屏
// if (orientationUtils.getScreenType() == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) {
// videoPlayer.getFullscreenButton().performClick();
// return;
// }
//釋放所有
videoPlayer.setVideoAllCallBack(null);
super.onBackPressed();
}
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/397406.html
標籤:其他
