diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a88c540..16eb52b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -62,6 +62,7 @@ + + + () { + + private val context = this + private lateinit var url: String + private var orientationUtils: OrientationUtils? = null + private var isPlay = false + private var isPause = false + + override fun initOnCreate(savedInstanceState: Bundle?) { + url = intent.getStringExtra(LiteKitConstant.INTENT_PARAM_KEY)!! + + //动态设置NormalGSYVideoPlayer宽高 + val rtspViewParams = binding.videoPlayer.layoutParams as ViewGroup.LayoutParams + val videoWidth = getScreenWidth() + val videoHeight = videoWidth * (9f / 16) + rtspViewParams.width = videoWidth + rtspViewParams.height = videoHeight.toInt() + binding.videoPlayer.layoutParams = rtspViewParams + binding.videoPlayer.titleTextView.visibility = View.GONE + + orientationUtils = OrientationUtils(this, binding.videoPlayer) + orientationUtils?.setEnable(false) + + val gsyVideoOption = GSYVideoOptionBuilder() + gsyVideoOption.apply { + setIsTouchWiget(true) + setRotateViewAuto(false) + setLockLand(false) + setShowFullAnimation(true) + setNeedLockFull(true) + setCacheWithPlay(false) + setUrl(url) + setVideoAllCallBack(object : GSYSampleCallBack() { + override fun onPrepared(url: String?, vararg objects: Any?) { + super.onPrepared(url, *objects) + //开始播放了才能旋转和全屏 + orientationUtils?.setEnable(true) + isPlay = true + } + + override fun onQuitFullscreen(url: String?, vararg objects: Any?) { + super.onQuitFullscreen(url, *objects) + orientationUtils?.backToProtVideo() + } + }) + setLockClickListener(object : LockClickListener { + override fun onClick(view: View?, lock: Boolean) { + orientationUtils?.setEnable(!lock) + } + }) + build(binding.videoPlayer) + } + binding.videoPlayer.startPlayLogic() + } + + override fun initViewBinding(): ActivitySafetyTreeVideoBinding { + return ActivitySafetyTreeVideoBinding.inflate(layoutInflater) + } + + override fun observeRequestState() { + + } + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + override fun initEvent() { + onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + orientationUtils?.backToProtVideo() + GSYVideoManager.backFromWindowFull(context) + } + }) + + binding.videoPlayer.backButton.setOnClickListener { + finish() + } + + binding.videoPlayer.fullscreenButton.setOnClickListener { + orientationUtils?.resolveByClick() + binding.videoPlayer.startWindowFullscreen(this, true, true) + binding.videoPlayer.startPlayLogic() + } + } + + override fun onPause() { + binding.videoPlayer.currentPlayer.onVideoPause() + super.onPause() + isPause = true + } + + override fun onResume() { + binding.videoPlayer.currentPlayer.onVideoResume(false) + super.onResume() + isPause = false + WindowCompat.getInsetsController(window, binding.rootView).apply { + hide(WindowInsetsCompat.Type.statusBars()) + hide(WindowInsetsCompat.Type.navigationBars()) + } + } + + override fun onDestroy() { + super.onDestroy() + if (isPlay) { + binding.videoPlayer.currentPlayer.release() + } + orientationUtils?.releaseListener() + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + if (isPlay && !isPause) { + binding.videoPlayer.onConfigurationChanged( + this, newConfig, orientationUtils, true, true + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index a88c540..16eb52b 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -62,6 +62,7 @@ + () { + + private val context = this + private lateinit var url: String + private var orientationUtils: OrientationUtils? = null + private var isPlay = false + private var isPause = false + + override fun initOnCreate(savedInstanceState: Bundle?) { + url = intent.getStringExtra(LiteKitConstant.INTENT_PARAM_KEY)!! + + //动态设置NormalGSYVideoPlayer宽高 + val rtspViewParams = binding.videoPlayer.layoutParams as ViewGroup.LayoutParams + val videoWidth = getScreenWidth() + val videoHeight = videoWidth * (9f / 16) + rtspViewParams.width = videoWidth + rtspViewParams.height = videoHeight.toInt() + binding.videoPlayer.layoutParams = rtspViewParams + binding.videoPlayer.titleTextView.visibility = View.GONE + + orientationUtils = OrientationUtils(this, binding.videoPlayer) + orientationUtils?.setEnable(false) + + val gsyVideoOption = GSYVideoOptionBuilder() + gsyVideoOption.apply { + setIsTouchWiget(true) + setRotateViewAuto(false) + setLockLand(false) + setShowFullAnimation(true) + setNeedLockFull(true) + setCacheWithPlay(false) + setUrl(url) + setVideoAllCallBack(object : GSYSampleCallBack() { + override fun onPrepared(url: String?, vararg objects: Any?) { + super.onPrepared(url, *objects) + //开始播放了才能旋转和全屏 + orientationUtils?.setEnable(true) + isPlay = true + } + + override fun onQuitFullscreen(url: String?, vararg objects: Any?) { + super.onQuitFullscreen(url, *objects) + orientationUtils?.backToProtVideo() + } + }) + setLockClickListener(object : LockClickListener { + override fun onClick(view: View?, lock: Boolean) { + orientationUtils?.setEnable(!lock) + } + }) + build(binding.videoPlayer) + } + binding.videoPlayer.startPlayLogic() + } + + override fun initViewBinding(): ActivitySafetyTreeVideoBinding { + return ActivitySafetyTreeVideoBinding.inflate(layoutInflater) + } + + override fun observeRequestState() { + + } + + override fun setupTopBarLayout() { + ImmersionBar.with(this).statusBarDarkFont(false).init() + } + + override fun initEvent() { + onBackPressedDispatcher.addCallback(object : OnBackPressedCallback(true) { + override fun handleOnBackPressed() { + orientationUtils?.backToProtVideo() + GSYVideoManager.backFromWindowFull(context) + } + }) + + binding.videoPlayer.backButton.setOnClickListener { + finish() + } + + binding.videoPlayer.fullscreenButton.setOnClickListener { + orientationUtils?.resolveByClick() + binding.videoPlayer.startWindowFullscreen(this, true, true) + binding.videoPlayer.startPlayLogic() + } + } + + override fun onPause() { + binding.videoPlayer.currentPlayer.onVideoPause() + super.onPause() + isPause = true + } + + override fun onResume() { + binding.videoPlayer.currentPlayer.onVideoResume(false) + super.onResume() + isPause = false + WindowCompat.getInsetsController(window, binding.rootView).apply { + hide(WindowInsetsCompat.Type.statusBars()) + hide(WindowInsetsCompat.Type.navigationBars()) + } + } + + override fun onDestroy() { + super.onDestroy() + if (isPlay) { + binding.videoPlayer.currentPlayer.release() + } + orientationUtils?.releaseListener() + } + + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + if (isPlay && !isPause) { + binding.videoPlayer.onConfigurationChanged( + this, newConfig, orientationUtils, true, true + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt index 69cd36c..5c6aafd 100644 --- a/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt +++ b/app/src/main/java/com/casic/br/operationsite/view/WorkSiteTabActivity.kt @@ -6,6 +6,7 @@ import android.util.Log import android.view.LayoutInflater import android.view.View +import android.widget.Button import android.widget.TextView import androidx.lifecycle.ViewModelProvider import com.amap.api.maps.AMap @@ -36,6 +37,7 @@ import com.pengxh.kt.lite.base.KotlinBaseActivity import com.pengxh.kt.lite.extensions.convertColor import com.pengxh.kt.lite.extensions.navigatePageTo +import com.pengxh.kt.lite.extensions.show import com.pengxh.kt.lite.extensions.timestampToCompleteDate import com.pengxh.kt.lite.extensions.timestampToTime import com.pengxh.kt.lite.utils.ActivityStackManager @@ -368,6 +370,7 @@ val deviceNameView = view.findViewById(R.id.deviceNameView) val alarmValueView = view.findViewById(R.id.alarmValueView) val timeView = view.findViewById(R.id.timeView) + val watchVideoButton = view.findViewById