Skip to content

Commit ffd9eb1

Browse files
committed
增加断开重新连接的处理
1 parent a3129e2 commit ffd9eb1

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,14 @@ open class VideoTestActivity : VideoBaseActivity(), XP2PCallback, CoroutineScope
8787
override fun initView() {
8888
productId = intent.getStringExtra("productId")?.toString() ?: ""
8989
deviceName = intent.getStringExtra("deviceName")?.toString() ?: ""
90-
xp2pInfo = intent.getStringExtra("p2pInfo")?.toString() ?: ""
91-
audioRecordUtil = AudioRecordUtil(this, "${productId}/${deviceName}", 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT)
90+
xp2pInfo = intent.getStringExtra("p2pInfo")?.toString() ?: ""
91+
audioRecordUtil = AudioRecordUtil(
92+
this,
93+
"${productId}/${deviceName}",
94+
16000,
95+
AudioFormat.CHANNEL_IN_MONO,
96+
AudioFormat.ENCODING_PCM_16BIT
97+
)
9298
XP2P.setCallback(this)
9399
XP2P.startService(this, "${productId}/${deviceName}", productId, deviceName)
94100

@@ -304,10 +310,33 @@ open class VideoTestActivity : VideoBaseActivity(), XP2PCallback, CoroutineScope
304310

305311
override fun xp2pEventNotify(id: String?, msg: String?, event: Int) {
306312
Log.e("VideoTestActivity", "xp2pEventNotify id:$id msg:$msg event:$event")
307-
if (event == 1004 || event == 1005) {
313+
if (event == 1003) {
314+
XP2P.stopService("${productId}/${deviceName}")
315+
XP2P.startService(this, "${productId}/${deviceName}", productId, deviceName)
316+
val ret = XP2P.setParamsForXp2pInfo(
317+
"${productId}/${deviceName}", "", "", xp2pInfo
318+
)
319+
if (ret != 0) {
320+
launch(Dispatchers.Main) {
321+
val errInfo: String
322+
if (ret.toString() == "-1007") {
323+
errInfo = getString(R.string.xp2p_err_version)
324+
} else {
325+
errInfo = getString(
326+
R.string.error_with_code,
327+
"${productId}/${deviceName}",
328+
ret.toString()
329+
)
330+
}
331+
Toast.makeText(this@VideoTestActivity, errInfo, Toast.LENGTH_SHORT).show()
332+
}
333+
}
334+
resetPlayer()
335+
} else if (event == 1004 || event == 1005) {
308336
if (event == 1004) {
309337
Log.e("VideoTestActivity", "====event === 1004")
310338
XP2P.delegateHttpFlv(id)?.let {
339+
XP2P.recordstream(id)
311340
urlPrefix = it
312341
if (!TextUtils.isEmpty(urlPrefix)) {
313342
resetPlayer()

0 commit comments

Comments
 (0)