Skip to content

Commit fad92d9

Browse files
committed
修复弱网情况下,获取不到预览链接的异常
Change-Id: I795706a21c3c79755957dcfd9cf6fde385aafab3
1 parent 86e98ab commit fad92d9

File tree

4 files changed

+21
-13
lines changed

4 files changed

+21
-13
lines changed

sdk/video-link-android/src/main/java/com/tencent/iot/video/link/util/audio/AudioRecordUtil.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ private void reset() {
6767
*/
6868
public void stop() {
6969
recorderState = false;
70-
audioRecord.stop();
70+
if (audioRecord != null) {
71+
audioRecord.stop();
72+
}
7173
audioRecord = null;
7274
}
7375

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,9 +80,11 @@ class VideoLocalPlaybackFragment: VideoPlaybackBaseFragment(), TextureView.Surfa
8080
@Volatile
8181
private var isShowing = false
8282

83-
private fun sendCmd(id: String, cmd: String):String {
83+
private fun sendCmd(id: String, cmd: String): String {
8484
if (connected)
85-
return XP2P.postCommandRequestSync(id, cmd.toByteArray(), cmd.toByteArray().size.toLong(), 2 * 1000 * 1000)
85+
XP2P.postCommandRequestSync(id, cmd.toByteArray(), cmd.toByteArray().size.toLong(), 2 * 1000 * 1000)?.let {
86+
return it
87+
}
8688
return ""
8789
}
8890

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

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,13 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
165165
countDownLatchs.put("${App.data.accessInfo!!.productId}/${presenter.getDeviceName()}", tmpCountDownLatch)
166166
tmpCountDownLatch.await()
167167

168-
urlPrefix = XP2P.delegateHttpFlv("${App.data.accessInfo!!.productId}/${presenter.getDeviceName()}")
169-
if (!TextUtils.isEmpty(urlPrefix)) {
170-
player?.let {
171-
resetPlayer()
172-
keepPlayerplay("${App.data.accessInfo!!.productId}/${presenter.getDeviceName()}")
168+
XP2P.delegateHttpFlv("${App.data.accessInfo!!.productId}/${presenter.getDeviceName()}")?.let {
169+
urlPrefix = it
170+
if (!TextUtils.isEmpty(urlPrefix)) {
171+
player?.let {
172+
resetPlayer()
173+
keepPlayerplay("${App.data.accessInfo!!.productId}/${presenter.getDeviceName()}")
174+
}
173175
}
174176
}
175177
}).start()
@@ -209,8 +211,10 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
209211
tmpCountDownLatch.await()
210212
Log.d(tag, "id=${id}, tmpCountDownLatch do not wait any more")
211213

212-
urlPrefix = XP2P.delegateHttpFlv(id)
213-
if (!TextUtils.isEmpty(urlPrefix)) resetPlayer()
214+
XP2P.delegateHttpFlv(id)?.let {
215+
urlPrefix = it
216+
if (!TextUtils.isEmpty(urlPrefix)) resetPlayer()
217+
}
214218
}
215219
}.start()
216220
}
@@ -235,7 +239,7 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
235239
if (able) {
236240
var command = Command.getNvrIpcStatus(presenter.getChannel(), 0)
237241
var repStatus = XP2P.postCommandRequestSync("${accessInfo.productId}/${presenter.getDeviceName()}",
238-
command.toByteArray(), command.toByteArray().size.toLong(), 2 * 1000 * 1000)
242+
command.toByteArray(), command.toByteArray().size.toLong(), 2 * 1000 * 1000) ?:""
239243

240244
launch(Dispatchers.Main) {
241245
var retContent = StringBuilder(repStatus).toString()
@@ -338,7 +342,7 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
338342
App.data.accessInfo?.let {
339343
if (command.length <= 0) return@Runnable
340344
var retContent = XP2P.postCommandRequestSync("${it.productId}/${presenter.getDeviceName()}",
341-
command.toByteArray(), command.toByteArray().size.toLong(), 2 * 1000 * 1000)
345+
command.toByteArray(), command.toByteArray().size.toLong(), 2 * 1000 * 1000)?:""
342346
launch(Dispatchers.Main) {
343347
if (TextUtils.isEmpty(retContent)) {
344348
retContent = getString(R.string.command_with_error, command)

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/video/utils/TipToastDialog.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public TipToastDialog(Context context, String content, long duration) {
3333
public void initView() {
3434
handler.postDelayed(() -> {
3535
if (isShowing()) {
36-
super.dismiss();
36+
dismiss();
3737
}
3838
}, duration);
3939

0 commit comments

Comments
 (0)