实时视频组件优化
This commit is contained in:
@@ -101,8 +101,6 @@ dependencies {
|
|||||||
implementation("com.yanzhenjie.recyclerview:x:1.3.2")
|
implementation("com.yanzhenjie.recyclerview:x:1.3.2")
|
||||||
//Android-PickerView-时间弹窗
|
//Android-PickerView-时间弹窗
|
||||||
implementation("com.contrarywind:Android-PickerView:4.1.9")
|
implementation("com.contrarywind:Android-PickerView:4.1.9")
|
||||||
//基于exoPlayer 自定义播放器 JPlayer支持功能
|
|
||||||
implementation("com.ycjiang:VideoPlayModule-Lite:2.3.61")
|
|
||||||
// GSYVideoPlayer
|
// GSYVideoPlayer
|
||||||
implementation("io.github.carguo:gsyvideoplayer:13.0.0")
|
implementation("io.github.carguo:gsyvideoplayer:13.0.0")
|
||||||
|
|
||||||
|
|||||||
@@ -90,6 +90,7 @@
|
|||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".liveVideo.LiveVideoActivity"
|
android:name=".liveVideo.LiveVideoActivity"
|
||||||
|
android:configChanges="orientation|screenSize|keyboardHidden"
|
||||||
android:exported="false" />
|
android:exported="false" />
|
||||||
<activity
|
<activity
|
||||||
android:name=".home.SetNameActivity"
|
android:name=".home.SetNameActivity"
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ package com.example.defenseapplication.liveVideo
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.pm.ActivityInfo
|
||||||
|
import android.content.res.Configuration
|
||||||
|
import android.graphics.Color
|
||||||
import android.media.AudioManager
|
import android.media.AudioManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
|
import androidx.core.view.isVisible
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager
|
import androidx.recyclerview.widget.LinearLayoutManager
|
||||||
import androidx.recyclerview.widget.RecyclerView
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.example.defenseapplication.R
|
import com.example.defenseapplication.R
|
||||||
@@ -25,7 +29,6 @@ import com.shuyu.gsyvideoplayer.listener.GSYSampleCallBack
|
|||||||
import com.shuyu.gsyvideoplayer.utils.OrientationUtils
|
import com.shuyu.gsyvideoplayer.utils.OrientationUtils
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.alibaba.sdk.android.emas.f
|
|
||||||
|
|
||||||
class LiveVideoActivity : BaseActivity() {
|
class LiveVideoActivity : BaseActivity() {
|
||||||
private lateinit var binding: LiveVideoActivityBinding
|
private lateinit var binding: LiveVideoActivityBinding
|
||||||
@@ -45,6 +48,8 @@ class LiveVideoActivity : BaseActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
Log.d("onEnterFullscreen", "onCreate")
|
||||||
|
|
||||||
binding = LiveVideoActivityBinding.inflate(layoutInflater)
|
binding = LiveVideoActivityBinding.inflate(layoutInflater)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
@@ -65,8 +70,23 @@ class LiveVideoActivity : BaseActivity() {
|
|||||||
fetchAlarmList()
|
fetchAlarmList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 这段代码重写了onConfigurationChanged方法,用于监听屏幕方向变化:
|
||||||
|
当屏幕旋转为横屏时,隐藏顶部栏(topBar)
|
||||||
|
当屏幕为竖屏时,显示顶部栏
|
||||||
|
目的是在横屏观看视频时提供更沉浸的全屏体验。
|
||||||
|
* */
|
||||||
|
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||||
|
super.onConfigurationChanged(newConfig)
|
||||||
|
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||||
|
binding.topBar.visibility = View.GONE
|
||||||
|
} else {
|
||||||
|
binding.topBar.visibility = View.VISIBLE
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun initVideoPlayer() {
|
private fun initVideoPlayer() {
|
||||||
val videoUrl = "https://www.w3schools.com/html/movie.mp4"
|
val videoUrl = "https://www.w3schools.com/html/movie.mp4"//"https://test-streams.mux.dev/x36xhzz/x36xhzz.m3u8"
|
||||||
|
|
||||||
orientationUtils = OrientationUtils(this, binding.exoPlayContextId)
|
orientationUtils = OrientationUtils(this, binding.exoPlayContextId)
|
||||||
orientationUtils?.isEnable = true
|
orientationUtils?.isEnable = true
|
||||||
@@ -74,12 +94,11 @@ class LiveVideoActivity : BaseActivity() {
|
|||||||
GSYVideoOptionBuilder()
|
GSYVideoOptionBuilder()
|
||||||
.setUrl(videoUrl)
|
.setUrl(videoUrl)
|
||||||
.setCacheWithPlay(false)
|
.setCacheWithPlay(false)
|
||||||
|
.setCacheWithPlay(false)
|
||||||
.setRotateViewAuto(true)
|
.setRotateViewAuto(true)
|
||||||
.setLockLand(false)
|
.setLockLand(false)
|
||||||
.setShowFullAnimation(true)
|
.setShowFullAnimation(true)
|
||||||
.setNeedShowWifiTip(false)
|
.setNeedShowWifiTip(false)
|
||||||
.setEnlargeImageRes(R.drawable.full_size)
|
|
||||||
.setShrinkImageRes(R.drawable.full_screen)
|
|
||||||
|
|
||||||
.setVideoAllCallBack(object : GSYSampleCallBack() {
|
.setVideoAllCallBack(object : GSYSampleCallBack() {
|
||||||
override fun onPrepared(url: String?, vararg objects: Any?) {
|
override fun onPrepared(url: String?, vararg objects: Any?) {
|
||||||
@@ -89,26 +108,45 @@ class LiveVideoActivity : BaseActivity() {
|
|||||||
|
|
||||||
override fun onQuitFullscreen(url: String?, vararg objects: Any?) {
|
override fun onQuitFullscreen(url: String?, vararg objects: Any?) {
|
||||||
super.onQuitFullscreen(url, *objects)
|
super.onQuitFullscreen(url, *objects)
|
||||||
|
|
||||||
orientationUtils?.backToProtVideo()
|
orientationUtils?.backToProtVideo()
|
||||||
}
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
.build(binding.exoPlayContextId)
|
.build(binding.exoPlayContextId)
|
||||||
|
hidePlayerControls()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
binding.exoPlayContextId.startPlayLogic()
|
binding.exoPlayContextId.startPlayLogic()
|
||||||
binding.exoPlayContextId.fullscreenButton.setOnClickListener {
|
binding.exoPlayContextId.fullscreenButton.setOnClickListener {
|
||||||
orientationUtils?.resolveByClick()
|
orientationUtils?.resolveByClick()
|
||||||
|
binding.exoPlayContextId.startWindowFullscreen(this, true, true)
|
||||||
binding.exoPlayContextId.startWindowFullscreen(this, true, true)?.let { fullPlayer ->
|
|
||||||
if (fullPlayer is MyGSYVideoPlayer) {
|
|
||||||
fullPlayer.onControlVisibilityChanged = { show ->
|
|
||||||
Log.e("GSY_TEST", "全屏回调 show=$show")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
private fun hidePlayerControls() {
|
||||||
|
binding.exoPlayContextId.backButton.visibility = View.GONE
|
||||||
|
binding.exoPlayContextId.titleTextView.visibility = View.GONE
|
||||||
|
binding.exoPlayContextId.startButton.visibility = View.GONE
|
||||||
|
|
||||||
|
binding.exoPlayContextId.findViewById<View>(
|
||||||
|
com.shuyu.gsyvideoplayer.R.id.current
|
||||||
|
)?.visibility = View.GONE
|
||||||
|
|
||||||
|
binding.exoPlayContextId.findViewById<View>(
|
||||||
|
com.shuyu.gsyvideoplayer.R.id.total
|
||||||
|
)?.visibility = View.GONE
|
||||||
|
|
||||||
|
binding.exoPlayContextId.findViewById<View>(
|
||||||
|
com.shuyu.gsyvideoplayer.R.id.progress
|
||||||
|
)?.visibility = View.INVISIBLE
|
||||||
|
|
||||||
|
binding.exoPlayContextId.findViewById<View>(
|
||||||
|
com.shuyu.gsyvideoplayer.R.id.start
|
||||||
|
)?.visibility = View.GONE
|
||||||
|
|
||||||
|
binding.exoPlayContextId.findViewById<View>(
|
||||||
|
com.shuyu.gsyvideoplayer.R.id.layout_bottom
|
||||||
|
)?.setBackgroundColor(Color.TRANSPARENT)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initAlarmRecyclerView() {
|
private fun initAlarmRecyclerView() {
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ class MyGSYVideoPlayer @JvmOverloads constructor(
|
|||||||
onControlVisibilityChanged?.invoke(true)
|
onControlVisibilityChanged?.invoke(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 暂停中显示控制栏
|
// 暂停中显示控制栏hideAllExceptFullscreen
|
||||||
override fun changeUiToPauseShow() {
|
override fun changeUiToPauseShow() {
|
||||||
super.changeUiToPauseShow()
|
super.changeUiToPauseShow()
|
||||||
onControlVisibilityChanged?.invoke(true)
|
onControlVisibilityChanged?.invoke(true)
|
||||||
@@ -31,7 +31,6 @@ class MyGSYVideoPlayer @JvmOverloads constructor(
|
|||||||
Log.e("GSY_TEST", "changeUiToPlayingClear")
|
Log.e("GSY_TEST", "changeUiToPlayingClear")
|
||||||
onControlVisibilityChanged?.invoke(false)
|
onControlVisibilityChanged?.invoke(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 暂停中清除控制栏
|
// 暂停中清除控制栏
|
||||||
override fun changeUiToPauseClear() {
|
override fun changeUiToPauseClear() {
|
||||||
super.changeUiToPauseClear()
|
super.changeUiToPauseClear()
|
||||||
@@ -59,4 +58,4 @@ class MyGSYVideoPlayer @JvmOverloads constructor(
|
|||||||
super.changeUiToPreparingShow()
|
super.changeUiToPreparingShow()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.example.defenseapplication.view
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.util.AttributeSet
|
||||||
|
import android.view.View
|
||||||
|
import com.shuyu.gsyvideoplayer.video.StandardGSYVideoPlayer
|
||||||
|
|
||||||
|
class MyGSYVideoPlayerLive @JvmOverloads constructor(
|
||||||
|
context: Context, attrs: AttributeSet? = null
|
||||||
|
) : StandardGSYVideoPlayer(context, attrs) {
|
||||||
|
|
||||||
|
override fun init(context: Context) {
|
||||||
|
super.init(context)
|
||||||
|
startButton.visibility = View.GONE
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun updateStartImage() {
|
||||||
|
startButton.visibility = View.GONE
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -43,12 +43,13 @@
|
|||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<!-- 视频播放区域 -->
|
|
||||||
<com.example.defenseapplication.view.MyGSYVideoPlayer
|
<com.example.defenseapplication.view.MyGSYVideoPlayerLive
|
||||||
android:id="@+id/exoPlayContextId"
|
android:id="@+id/exoPlayContextId"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="280dp"/>
|
android:layout_height="280dp"/>
|
||||||
|
|
||||||
|
|
||||||
<!-- 功能按钮区域 -->
|
<!-- 功能按钮区域 -->
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/functionBar"
|
android:id="@+id/functionBar"
|
||||||
|
|||||||
Reference in New Issue
Block a user