...
|
...
|
@@ -2,9 +2,14 @@ package com.br_technology.securitytrain_master.view |
|
|
|
|
|
import android.app.Activity
|
|
|
import android.content.Context
|
|
|
import android.content.pm.ActivityInfo
|
|
|
import android.content.res.Configuration
|
|
|
import android.os.Build
|
|
|
import android.text.TextUtils
|
|
|
import android.util.AttributeSet
|
|
|
import android.util.TypedValue
|
|
|
import android.view.ViewGroup
|
|
|
import android.view.WindowManager
|
|
|
import android.widget.ImageView
|
|
|
import androidx.lifecycle.Lifecycle
|
|
|
import androidx.lifecycle.LifecycleObserver
|
...
|
...
|
@@ -29,8 +34,13 @@ class MyVideoPlayer : StandardGSYVideoPlayer, LifecycleObserver { |
|
|
private var isPause = false
|
|
|
private var canTouchProgress = false
|
|
|
|
|
|
private var isFull = false
|
|
|
|
|
|
private var orientationUtils: OrientationUtils? = null
|
|
|
|
|
|
//全屏点击事件
|
|
|
private var fullOnClickListener: ((t: Boolean) -> Unit?)? = null
|
|
|
|
|
|
constructor(context: Context) : super(context)
|
|
|
constructor(context: Context, fullFlag: Boolean) : super(context, fullFlag)
|
|
|
constructor(context: Context, attributeSet: AttributeSet) : super(context, attributeSet)
|
...
|
...
|
@@ -67,11 +77,19 @@ class MyVideoPlayer : StandardGSYVideoPlayer, LifecycleObserver { |
|
|
// }
|
|
|
if (this.fullscreenButton != null) {
|
|
|
this.fullscreenButton.setOnClickListener {
|
|
|
showFull()
|
|
|
showFull(activity)
|
|
|
}
|
|
|
}
|
|
|
if (this.mBackButton != null) {
|
|
|
this.mBackButton.setOnClickListener {
|
|
|
if(isFull){
|
|
|
showFull(activity)
|
|
|
}else{
|
|
|
activity.finish()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
initPlayer()
|
|
|
mProgressBar.isEnabled = canTouchProgress
|
|
|
}
|
|
|
|
|
|
private fun initPlayer() {
|
...
|
...
|
@@ -88,23 +106,100 @@ class MyVideoPlayer : StandardGSYVideoPlayer, LifecycleObserver { |
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 禁止拖动
|
|
|
*/
|
|
|
fun setCantTouch(bool: Boolean) {
|
|
|
canTouchProgress = bool
|
|
|
mProgressBar.isEnabled = canTouchProgress
|
|
|
}
|
|
|
|
|
|
private fun showFull() {
|
|
|
if (orientationUtils!!.isLand != 1) {
|
|
|
private fun showFull(activity: Activity) {
|
|
|
//第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
|
|
|
// this.startWindowFullscreen(
|
|
|
// context,
|
|
|
// true,
|
|
|
// true
|
|
|
// )
|
|
|
fullOnClickListener?.invoke(isFull)
|
|
|
changeWindow(activity)
|
|
|
}
|
|
|
|
|
|
fun setFullOnClick(listener: (t: Boolean) -> Unit) {
|
|
|
fullOnClickListener = listener
|
|
|
}
|
|
|
|
|
|
fun changeWindow(activity: Activity) {
|
|
|
if (!isFull) {
|
|
|
changeToFull(activity)
|
|
|
} else {
|
|
|
changeToPort(activity)
|
|
|
}
|
|
|
isFull = !isFull
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 全屏
|
|
|
*/
|
|
|
fun changeToFull(activity: Activity) {
|
|
|
// if (orientationUtils!!.isLand != 1) {
|
|
|
//直接横屏
|
|
|
orientationUtils!!.resolveByClick()
|
|
|
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
|
|
// orientationUtils!!.resolveByClick()
|
|
|
// }
|
|
|
hideNavigationBar(activity)
|
|
|
hideStatusBar(activity)
|
|
|
val vlp: ViewGroup.LayoutParams = this.layoutParams
|
|
|
vlp.width = ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
vlp.height = ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
}
|
|
|
//第一个true是否需要隐藏actionbar,第二个true是否需要隐藏statusbar
|
|
|
this.startWindowFullscreen(
|
|
|
context,
|
|
|
true,
|
|
|
true
|
|
|
|
|
|
/**
|
|
|
* 竖屏
|
|
|
*/
|
|
|
fun changeToPort(activity: Activity) {
|
|
|
activity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
|
|
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN)
|
|
|
activity.window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS)
|
|
|
val vlp: ViewGroup.LayoutParams = this.getLayoutParams()
|
|
|
vlp.width = ViewGroup.LayoutParams.MATCH_PARENT
|
|
|
vlp.height = TypedValue.applyDimension(
|
|
|
TypedValue.COMPLEX_UNIT_DIP,
|
|
|
200F,
|
|
|
getResources().getDisplayMetrics()
|
|
|
).toInt()
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
fun hideNavigationBar(activity: Activity) {
|
|
|
val uiOptions = activity.window.decorView.systemUiVisibility
|
|
|
activity.window.decorView.systemUiVisibility = uiOptions or SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 隐藏状态栏
|
|
|
*/
|
|
|
fun hideStatusBar(activity: Activity) {
|
|
|
activity.window.setFlags(
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN,
|
|
|
WindowManager.LayoutParams.FLAG_FULLSCREEN
|
|
|
)
|
|
|
activity.window.setFlags(
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
|
|
|
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS
|
|
|
)
|
|
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
|
|
val decorView = activity.window.decorView
|
|
|
val uiOptions = (SYSTEM_UI_FLAG_FULLSCREEN
|
|
|
or SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
|
|
or SYSTEM_UI_FLAG_IMMERSIVE
|
|
|
or SYSTEM_UI_FLAG_IMMERSIVE_STICKY)
|
|
|
decorView.systemUiVisibility = uiOptions
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 选择builder模式
|
...
|
...
|
@@ -123,7 +218,7 @@ class MyVideoPlayer : StandardGSYVideoPlayer, LifecycleObserver { |
|
|
override fun onPrepared(url: String?, vararg objects: Any?) {
|
|
|
super.onPrepared(url, *objects)
|
|
|
//开始播放了才能旋转和全屏
|
|
|
orientationUtils!!.isEnable = true
|
|
|
// orientationUtils!!.isEnable = true
|
|
|
isPlay = true
|
|
|
}
|
|
|
|
...
|
...
|
@@ -160,7 +255,7 @@ class MyVideoPlayer : StandardGSYVideoPlayer, LifecycleObserver { |
|
|
.setUrl(mp4)
|
|
|
.setCacheWithPlay(true)
|
|
|
.setVideoTitle("")
|
|
|
.setIsTouchWiget(true)
|
|
|
.setIsTouchWiget(false)
|
|
|
.setRotateViewAuto(false)
|
|
|
.setLockLand(false)
|
|
|
.setShowFullAnimation(false)//打开动画
|
...
|
...
|
@@ -216,17 +311,36 @@ class MyVideoPlayer : StandardGSYVideoPlayer, LifecycleObserver { |
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
/**
|
|
|
* 全屏
|
|
|
*/
|
|
|
fun onConfigurationChanged(newConfig: Configuration, activity: Activity) {
|
|
|
//如果旋转了就全屏
|
|
|
if (isPlay && !isPause) {
|
|
|
this.onConfigurationChanged(
|
|
|
activity,
|
|
|
newConfig,
|
|
|
orientationUtils,
|
|
|
true,
|
|
|
true
|
|
|
)
|
|
|
}
|
|
|
// val orientation= newConfig.orientation
|
|
|
// if (orientation > 340 || orientation < 20) {
|
|
|
// //0
|
|
|
// changeToPort(activity)
|
|
|
// } else if (orientation in 71..109) {
|
|
|
// //90
|
|
|
// changeToFull(activity)
|
|
|
// } else if (orientation in 161..199) {
|
|
|
// //180
|
|
|
// changeToPort(activity)
|
|
|
// } else if (orientation in 251..289) {
|
|
|
// changeToFull(activity)
|
|
|
//
|
|
|
// //270
|
|
|
// }
|
|
|
|
|
|
// if (isPlay && !isPause) {
|
|
|
// this.onConfigurationChanged(
|
|
|
// activity,
|
|
|
// newConfig,
|
|
|
// orientationUtils,
|
|
|
// true,
|
|
|
// true
|
|
|
// )
|
|
|
// }
|
|
|
// changeWindow(activity)
|
|
|
}
|
|
|
} |
...
|
...
|
|