Skip to content

Commit 2904970

Browse files
sevenhhesevenhhe
authored andcommitted
后台过程中不继续预览或者多屏预览,从预览界面进入回放再返回至预览
https://docs.qq.com/doc/DVmFnR2ZIZW1ZU1Fo Change-Id: I21b5a292187704e39a02317cde1ef94ac65f0e61
1 parent b11c614 commit 2904970

File tree

3 files changed

+67
-30
lines changed

3 files changed

+67
-30
lines changed

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/playback/localPlayback/VideoLocalPlaybackFragment.kt

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,7 @@ import com.tencent.iot.explorer.link.demo.core.entity.DevVideoHistory
2424
import com.tencent.iot.explorer.link.demo.video.Command
2525
import com.tencent.iot.explorer.link.demo.video.CommandResp
2626
import com.tencent.iot.explorer.link.demo.video.DevInfo
27-
import com.tencent.iot.explorer.link.demo.video.playback.BottomPlaySpeedDialog
28-
import com.tencent.iot.explorer.link.demo.video.playback.CalendarDialog
29-
import com.tencent.iot.explorer.link.demo.video.playback.RightPlaySpeedDialog
30-
import com.tencent.iot.explorer.link.demo.video.playback.VideoPlaybackBaseFragment
27+
import com.tencent.iot.explorer.link.demo.video.playback.*
3128
import com.tencent.iot.explorer.link.demo.video.utils.ToastDialog
3229
import com.tencent.xnet.XP2P
3330
import com.tencent.xnet.XP2PCallback
@@ -634,8 +631,24 @@ class VideoLocalPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
634631
}
635632
}
636633

637-
override fun onDestroy() {
638-
super.onDestroy()
634+
override fun onPause() {
635+
super.onPause()
636+
if (context is VideoPlaybackActivity) {
637+
if ((context as VideoPlaybackActivity).isFinishing) {
638+
finishAll()
639+
return
640+
}
641+
}
642+
player?.let {
643+
if (currentPlayerState) {
644+
launch (Dispatchers.Main) {
645+
iv_start.performClick()
646+
}
647+
}
648+
}
649+
}
650+
651+
private fun finishAll() {
639652
player?.release()
640653

641654
if (recordingState) {

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/preview/VideoMultiPreviewActivity.kt

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.tencent.iot.explorer.link.demo.video.preview
33
import android.content.Context
44
import android.content.Intent
55
import android.content.pm.ActivityInfo
6+
import android.content.res.Configuration
67
import android.graphics.SurfaceTexture
78
import android.os.Bundle
89
import android.text.TextUtils
@@ -43,11 +44,21 @@ class VideoMultiPreviewActivity : VideoBaseActivity(), XP2PCallback, CoroutineSc
4344
lateinit var linearLayoutManager : LinearLayoutManager
4445
private var adapter : DevPreviewAdapter? = null
4546
private var tag = VideoMultiPreviewActivity::class.simpleName
47+
private var orientation = true
4648

4749
override fun getContentView(): Int {
4850
return R.layout.activity_video_multi_preview
4951
}
5052

53+
override fun onResume() {
54+
super.onResume()
55+
adapter = DevPreviewAdapter(this@VideoMultiPreviewActivity, allDevUrl)
56+
gl_video.layoutManager = linearLayoutManager
57+
gl_video.adapter = adapter
58+
switchOrientation(orientation)
59+
playAll()
60+
}
61+
5162
override fun initView() {
5263
App.data.accessInfo?.let {
5364
XP2P.setQcloudApiCred(it.accessId, it.accessToken)
@@ -64,10 +75,6 @@ class VideoMultiPreviewActivity : VideoBaseActivity(), XP2PCallback, CoroutineSc
6475
if (allDevUrl.size <= 1) column = 1 // 当只有一个元素的时候,网格只有一列
6576
gridLayoutManager = GridLayoutManager(this@VideoMultiPreviewActivity, column)
6677
linearLayoutManager = LinearLayoutManager(this@VideoMultiPreviewActivity)
67-
adapter = DevPreviewAdapter(this@VideoMultiPreviewActivity, allDevUrl)
68-
gl_video.layoutManager = linearLayoutManager
69-
gl_video.adapter = adapter
70-
playAll()
7178
} catch (e : Exception) {
7279
e.printStackTrace()
7380
}
@@ -81,14 +88,14 @@ class VideoMultiPreviewActivity : VideoBaseActivity(), XP2PCallback, CoroutineSc
8188
if (App.data.accessInfo == null) return
8289

8390
for (i in 0 until allDevUrl.size) {
84-
if (allDevUrl.get(i).Status != 1) continue
91+
if (allDevUrl[i].Status != 1) continue
8592

8693
var player = IjkMediaPlayer()
87-
allDevUrl.get(i).surfaceTextureListener = object : TextureView.SurfaceTextureListener {
94+
allDevUrl[i].surfaceTextureListener = object : TextureView.SurfaceTextureListener {
8895
override fun onSurfaceTextureAvailable(surface: SurfaceTexture?, width: Int, height: Int) {
8996
surface?.let {
90-
allDevUrl.get(i).surface = Surface(surface)
91-
player.setSurface(allDevUrl.get(i).surface)
97+
allDevUrl[i].surface = Surface(surface)
98+
player.setSurface(allDevUrl[i].surface)
9299
}
93100
}
94101

@@ -97,7 +104,7 @@ class VideoMultiPreviewActivity : VideoBaseActivity(), XP2PCallback, CoroutineSc
97104
override fun onSurfaceTextureUpdated(surface: SurfaceTexture?) {}
98105
}
99106

100-
setPlayerSource(player, allDevUrl.get(i).devName, allDevUrl.get(i).channel)
107+
setPlayerSource(player, allDevUrl[i].devName, allDevUrl[i].channel)
101108
allDevUrl.get(i).player = player
102109
}
103110
}
@@ -169,6 +176,7 @@ class VideoMultiPreviewActivity : VideoBaseActivity(), XP2PCallback, CoroutineSc
169176
radio_orientation_h.visibility = View.GONE
170177
gl_video.layoutManager = gridLayoutManager
171178
}
179+
orientation = orientationV
172180
adapter?.notifyDataSetChanged()
173181
}
174182

@@ -300,9 +308,12 @@ class VideoMultiPreviewActivity : VideoBaseActivity(), XP2PCallback, CoroutineSc
300308
override fun avDataRecvHandle(id: String?, data: ByteArray?, len: Int) {}
301309
override fun avDataCloseHandle(id: String?, msg: String?, errorCode: Int) {}
302310

303-
override fun onDestroy() {
304-
super.onDestroy()
311+
override fun onPause() {
312+
super.onPause()
313+
finishAll()
314+
}
305315

316+
private fun finishAll() {
306317
for (devPlayer in allDevUrl) {
307318
devPlayer.player?.release()
308319
}
@@ -313,7 +324,6 @@ class VideoMultiPreviewActivity : VideoBaseActivity(), XP2PCallback, CoroutineSc
313324
}
314325
}
315326

316-
XP2P.setCallback(null)
317327
countDownLatchs.clear()
318328

319329
// 关闭所有守护线程
@@ -325,6 +335,12 @@ class VideoMultiPreviewActivity : VideoBaseActivity(), XP2PCallback, CoroutineSc
325335
}
326336
}
327337
}
338+
}
339+
340+
override fun onDestroy() {
341+
super.onDestroy()
342+
finishAll()
343+
XP2P.setCallback(null)
328344
cancel()
329345
}
330346

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/preview/VideoPreviewActivity.kt

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,14 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
9191
return R.layout.activity_video_preview
9292
}
9393

94-
override fun initView() {
94+
override fun onResume() {
95+
super.onResume()
96+
XP2P.setCallback(this)
9597
keepAliveThreadRuning = true
98+
startPlayer()
99+
}
100+
101+
override fun initView() {
96102
presenter = EventPresenter(this@VideoPreviewActivity)
97103
var bundle = intent.getBundleExtra(VideoConst.VIDEO_CONFIG)
98104
bundle?.let {
@@ -123,16 +129,9 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
123129
tv_event_status.visibility = View.VISIBLE
124130
tv_event_status.setText(R.string.loading)
125131
XP2P.setQcloudApiCred(it.accessId, it.accessToken)
126-
XP2P.setCallback(this)
127132
audioRecordUtil = AudioRecordUtil(this, "${it.productId}/${presenter.getDeviceName()}")
128133
}
129134

130-
startPlayer()
131-
if (player != null) {
132-
mHandler.sendEmptyMessageDelayed(MSG_UPDATE_HUD, 500)
133-
} else {
134-
mHandler.removeMessages(MSG_UPDATE_HUD)
135-
}
136135
//实例化对象并设置监听器
137136
volumeChangeObserver = VolumeChangeObserver(this)
138137
volumeChangeObserver?.setVolumeChangeListener(this)
@@ -142,6 +141,7 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
142141
private fun startPlayer() {
143142
if (App.data.accessInfo == null || TextUtils.isEmpty(presenter.getDeviceName())) return
144143
player = IjkMediaPlayer()
144+
mHandler.sendEmptyMessageDelayed(MSG_UPDATE_HUD, 500)
145145

146146
Thread(Runnable {
147147
var id = "${App.data.accessInfo!!.productId}/${presenter.getDeviceName()}"
@@ -295,7 +295,6 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
295295
var dev = DevInfo()
296296
dev.deviceName = presenter.getDeviceName()
297297
VideoPlaybackActivity.startPlaybackActivity(this@VideoPreviewActivity, dev)
298-
finish()
299298
}
300299
radio_photo.setOnClickListener {
301300
ImageSelect.saveBitmap(this@VideoPreviewActivity, v_preview.bitmap)
@@ -532,9 +531,13 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
532531
}
533532
}
534533

535-
override fun onDestroy() {
536-
super.onDestroy()
534+
override fun onPause() {
535+
super.onPause()
536+
finishPlayer()
537+
}
537538

539+
private fun finishPlayer() {
540+
mHandler.removeMessages(MSG_UPDATE_HUD)
538541
player?.release()
539542
if (radio_talk.isChecked) speakAble(false)
540543
if (radio_record.isChecked) {
@@ -545,7 +548,6 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
545548
App.data.accessInfo?.let {
546549
XP2P.stopService("${it.productId}/${presenter.getDeviceName()}")
547550
}
548-
XP2P.setCallback(null)
549551

550552
countDownLatchs.clear()
551553
// 关闭守护线程
@@ -555,6 +557,12 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
555557
it.notify()
556558
}
557559
}
560+
}
561+
562+
override fun onDestroy() {
563+
super.onDestroy()
564+
finishPlayer()
565+
XP2P.setCallback(null)
558566
cancel()
559567
volumeChangeObserver?.unregisterReceiver();
560568
}

0 commit comments

Comments
 (0)