设备告警日志功能逻辑
This commit is contained in:
@@ -42,6 +42,10 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
private var isLightOn = false
|
||||
private var deviceId: String? = null
|
||||
private var isLoading = false
|
||||
private var fromLiveVideo = false
|
||||
private var passedVideoUrl: String? = null
|
||||
private var passedSelectedId: String? = null
|
||||
private var passedCreateTime: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -53,6 +57,10 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
.init()
|
||||
|
||||
deviceId = intent.getStringExtra("device_id")
|
||||
fromLiveVideo = intent.getBooleanExtra("from_live_video", false)
|
||||
passedVideoUrl = intent.getStringExtra("video_url")
|
||||
passedSelectedId = intent.getStringExtra("selected_id")
|
||||
passedCreateTime = intent.getStringExtra("create_time")
|
||||
calendar = Calendar.getInstance()
|
||||
updateDateDisplay()
|
||||
initVideoPlayer()
|
||||
@@ -77,9 +85,14 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
|
||||
private fun initVideoPlayer() {
|
||||
val videoPlayerView = binding.exoPlayContextId
|
||||
val videoUri = if (fromLiveVideo && !passedVideoUrl.isNullOrEmpty()) {
|
||||
passedVideoUrl!!
|
||||
} else {
|
||||
"https://media.w3.org/2010/05/sintel/trailer.mp4"
|
||||
}
|
||||
|
||||
exoPlayerManager = VideoPlayerManager.Builder(VideoPlayerManager.TYPE_PLAY_GESTURE, videoPlayerView)
|
||||
.setPlayUri("https://media.w3.org/2010/05/sintel/trailer.mp4")
|
||||
.setPlayUri(videoUri)
|
||||
.setPosition(0)
|
||||
.addVideoInfoListener(object : VideoInfoListener {
|
||||
override fun onPlayStart(p0: Long) {
|
||||
@@ -87,7 +100,6 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun onLoadingChanged() {
|
||||
// 视频加载状态变化
|
||||
}
|
||||
|
||||
override fun onPlayerError(p0: com.google.android.exoplayer2.ExoPlaybackException?) {
|
||||
@@ -99,11 +111,9 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
override fun isPlaying(p0: Boolean) {
|
||||
// p0 表示当前是否正在播放
|
||||
}
|
||||
|
||||
fun onRepeatModeChanged(p0: Int) {
|
||||
// 循环模式改变时的回调
|
||||
}
|
||||
})
|
||||
.create()
|
||||
@@ -145,10 +155,49 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
}
|
||||
|
||||
private fun initRecyclerView() {
|
||||
adapter = AlarmLogAdapter(alarmList)
|
||||
adapter = AlarmLogAdapter(alarmList) { item ->
|
||||
if (!item.video.isNullOrEmpty()) {
|
||||
playVideo(item.video!!)
|
||||
} else {
|
||||
Toast.makeText(this, "该告警记录没有视频", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
}
|
||||
binding.alarmListRecyclerView.layoutManager = LinearLayoutManager(this)
|
||||
binding.alarmListRecyclerView.adapter = adapter
|
||||
}
|
||||
|
||||
private fun playVideo(videoUrl: String) {
|
||||
exoPlayerManager.onDestroy()
|
||||
|
||||
exoPlayerManager = VideoPlayerManager.Builder(VideoPlayerManager.TYPE_PLAY_GESTURE, binding.exoPlayContextId)
|
||||
.setPlayUri(videoUrl)
|
||||
.setPosition(0)
|
||||
.addVideoInfoListener(object : VideoInfoListener {
|
||||
override fun onPlayStart(p0: Long) {
|
||||
Log.d("AlarmLogActivity", "视频开始播放")
|
||||
}
|
||||
|
||||
override fun onLoadingChanged() {
|
||||
}
|
||||
|
||||
override fun onPlayerError(p0: com.google.android.exoplayer2.ExoPlaybackException?) {
|
||||
Toast.makeText(this@AlarmLogActivity, "播放失败", Toast.LENGTH_SHORT).show()
|
||||
}
|
||||
|
||||
override fun onPlayEnd() {
|
||||
Log.d("AlarmLogActivity", "播放结束")
|
||||
}
|
||||
|
||||
override fun isPlaying(p0: Boolean) {
|
||||
}
|
||||
|
||||
fun onRepeatModeChanged(p0: Int) {
|
||||
}
|
||||
})
|
||||
.create()
|
||||
|
||||
exoPlayerManager.startPlayer()
|
||||
}
|
||||
|
||||
private fun fetchAlarmList() {
|
||||
val currentDeviceId = deviceId ?: return
|
||||
@@ -297,6 +346,7 @@ class AlarmLogActivity : AppCompatActivity() {
|
||||
.setTextColorCenter(Color.parseColor("#09C2BD"))//选中颜色
|
||||
.setLineSpacingMultiplier(2.5f)//行间距倍数
|
||||
.setItemVisibleCount(5)//可见项数量
|
||||
.setDate(calendar) // 设置默认选中日期为tvDate显示的日期
|
||||
.build()
|
||||
timePicker.show()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user