视频组件优化
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
package com.example.defenseapplication.liveVideo
|
||||
|
||||
import android.content.Intent
|
||||
import android.content.res.Configuration
|
||||
import android.graphics.Color
|
||||
import android.os.Bundle
|
||||
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Toast
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
@@ -13,9 +16,11 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import chuangyuan.ycj.videolibrary.listener.VideoInfoListener
|
||||
import chuangyuan.ycj.videolibrary.video.ExoUserPlayer
|
||||
import chuangyuan.ycj.videolibrary.video.VideoPlayerManager
|
||||
import com.google.android.exoplayer2.ui.PlayerView
|
||||
import com.example.defenseapplication.R
|
||||
import com.example.defenseapplication.adapter.AlarmLogAdapter
|
||||
import com.example.defenseapplication.databinding.AlarmLogActivityBinding
|
||||
import com.example.defenseapplication.utils.ActivityManager
|
||||
import com.gyf.immersionbar.ImmersionBar
|
||||
import java.util.*
|
||||
import com.bigkoo.pickerview.builder.TimePickerBuilder
|
||||
@@ -28,6 +33,9 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
private var adapter: AlarmLogAdapter? = null
|
||||
private val alarmList = mutableListOf<String>()
|
||||
private lateinit var exoPlayerManager: ExoUserPlayer
|
||||
private var isMuted = false
|
||||
private var isVoiceEnabled = false
|
||||
private var isLightOn = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -94,6 +102,39 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
.create()
|
||||
|
||||
exoPlayerManager.startPlayer()
|
||||
|
||||
setupControllerVisibilityListener()
|
||||
}
|
||||
|
||||
private fun setupControllerVisibilityListener() {
|
||||
binding.exoPlayContextId.post {
|
||||
val playerView = findPlayerView(binding.exoPlayContextId)
|
||||
playerView?.setControllerVisibilityListener { visibility ->
|
||||
if (visibility == View.VISIBLE) {
|
||||
binding.muteBar.visibility = View.VISIBLE
|
||||
binding.functionBar.visibility = View.VISIBLE
|
||||
} else {
|
||||
binding.muteBar.visibility = View.GONE
|
||||
binding.functionBar.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun findPlayerView(view: View): PlayerView? {
|
||||
if (view is PlayerView) {
|
||||
return view
|
||||
}
|
||||
if (view is ViewGroup) {
|
||||
for (i in 0 until view.childCount) {
|
||||
val child = view.getChildAt(i)
|
||||
val found = findPlayerView(child)
|
||||
if (found != null) {
|
||||
return found
|
||||
}
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
private fun initRecyclerView() {
|
||||
@@ -122,6 +163,37 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
binding.expandImg.setOnClickListener {
|
||||
showDatePicker()
|
||||
}
|
||||
|
||||
binding.ivMute.setOnClickListener {
|
||||
toggleMute()
|
||||
}
|
||||
|
||||
binding.ivDownload.setOnClickListener {
|
||||
downloadVideo()
|
||||
}
|
||||
|
||||
binding.ivDelete.setOnClickListener {
|
||||
deleteVideo()
|
||||
}
|
||||
}
|
||||
|
||||
private fun toggleMute() {
|
||||
isMuted = !isMuted
|
||||
if (isMuted) {
|
||||
binding.ivMute.setImageResource(R.drawable.mute)
|
||||
Toast.makeText(this, R.string.sound_off, Toast.LENGTH_SHORT).show()
|
||||
} else {
|
||||
binding.ivMute.setImageResource(R.drawable.voice)
|
||||
Toast.makeText(this, R.string.sound_on, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
|
||||
private fun downloadVideo() {
|
||||
Toast.makeText(this, R.string.download, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
private fun deleteVideo() {
|
||||
Toast.makeText(this, R.string.delete, Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
@@ -141,12 +213,12 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
|
||||
|
||||
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
|
||||
// 进入横屏(全屏)模式
|
||||
binding.titleLayout.visibility = View.GONE
|
||||
binding.alarmListRecyclerView.visibility = View.GONE
|
||||
|
||||
|
||||
val params = binding.exoPlayContextId.layoutParams
|
||||
params.width = LinearLayout.LayoutParams.MATCH_PARENT
|
||||
params.height = LinearLayout.LayoutParams.MATCH_PARENT
|
||||
@@ -155,13 +227,13 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
// 进入竖屏(非全屏)模式
|
||||
binding.titleLayout.visibility = View.VISIBLE
|
||||
binding.alarmListRecyclerView.visibility = View.VISIBLE
|
||||
|
||||
|
||||
val params = binding.exoPlayContextId.layoutParams
|
||||
params.width = LinearLayout.LayoutParams.MATCH_PARENT
|
||||
params.height = dpToPx(250)
|
||||
params.height = dpToPx(280)
|
||||
binding.exoPlayContextId.layoutParams = params
|
||||
}
|
||||
|
||||
|
||||
exoPlayerManager.onConfigurationChanged(newConfig)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user