Skip to content

Commit ee07be0

Browse files
author
archurtan
committed
Video SDK Demo 预览页添加dash board
Change-Id: I9c2648748822fb986d8d558020463d5e77ee589a
1 parent d43cdd2 commit ee07be0

File tree

4 files changed

+151
-3
lines changed

4 files changed

+151
-3
lines changed

sdkdemo/src/main/java/com/tencent/iot/explorer/link/demo/common/util/CommonUtils.kt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import android.net.Uri
77
import android.os.Environment
88
import android.provider.MediaStore
99
import com.tencent.iot.explorer.link.demo.R
10-
import com.tencent.iot.explorer.link.demo.core.entity.TimeBlock
11-
import com.tencent.iot.explorer.link.demo.video.utils.ToastDialog
1210
import com.tencent.iot.explorer.link.demo.common.customView.CalendarView
1311
import com.tencent.iot.explorer.link.demo.common.customView.timeline.TimeBlockInfo
12+
import com.tencent.iot.explorer.link.demo.core.entity.TimeBlock
13+
import com.tencent.iot.explorer.link.demo.video.utils.ToastDialog
1414
import java.io.File
1515
import java.text.ParseException
1616
import java.text.SimpleDateFormat
@@ -109,5 +109,40 @@ class CommonUtils {
109109
// localContentValues.put("_size", paramLong)
110110
return localContentValues
111111
}
112+
113+
fun formatedDurationMilli(duration: Long): String {
114+
return if (duration >= 1000) {
115+
String.format(Locale.US, "%.2f sec", duration.toFloat() / 1000)
116+
} else {
117+
String.format(Locale.US, "%d msec", duration)
118+
}
119+
}
120+
121+
fun formatedSpeed(bytes: Long, elapsed_milli: Long): String {
122+
if (elapsed_milli <= 0) {
123+
return "0 B/s"
124+
}
125+
if (bytes <= 0) {
126+
return "0 B/s"
127+
}
128+
val bytes_per_sec = bytes.toFloat() * 1000f / elapsed_milli
129+
return if (bytes_per_sec >= 1000 * 1000) {
130+
String.format(Locale.US, "%.2f MB/s", bytes_per_sec / 1000 / 1000)
131+
} else if (bytes_per_sec >= 1000) {
132+
String.format(Locale.US, "%.1f KB/s", bytes_per_sec / 1000)
133+
} else {
134+
String.format(Locale.US, "%d B/s", bytes_per_sec.toLong())
135+
}
136+
}
137+
138+
fun formatedSize(bytes: Long): String? {
139+
return if (bytes >= 100 * 1000) {
140+
String.format(Locale.US, "%.2f MB", bytes.toFloat() / 1000 / 1000)
141+
} else if (bytes >= 100) {
142+
String.format(Locale.US, "%.1f KB", bytes.toFloat() / 1000)
143+
} else {
144+
String.format(Locale.US, "%d B", bytes)
145+
}
146+
}
112147
}
113148
}

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

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import android.content.pm.ActivityInfo
88
import android.graphics.SurfaceTexture
99
import android.media.AudioManager
1010
import android.os.Bundle
11+
import android.os.Handler
12+
import android.os.Message
1113
import android.text.TextUtils
1214
import android.util.Log
1315
import android.view.Surface
@@ -39,6 +41,7 @@ import com.tencent.iot.video.link.util.audio.AudioRecordUtil
3941
import com.tencent.xnet.XP2P
4042
import com.tencent.xnet.XP2PCallback
4143
import kotlinx.android.synthetic.main.activity_video_preview.*
44+
import kotlinx.android.synthetic.main.dash_board_layout.*
4245
import kotlinx.android.synthetic.main.fragment_video_cloud_playback.*
4346
import kotlinx.android.synthetic.main.title_layout.*
4447
import kotlinx.coroutines.*
@@ -82,6 +85,7 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
8285
@Volatile
8386
private var showVideoTime = 0L
8487
private var volumeChangeObserver: VolumeChangeObserver? = null
88+
private val MSG_UPDATE_HUD = 1
8589

8690
override fun getContentView(): Int {
8791
return R.layout.activity_video_preview
@@ -124,7 +128,11 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
124128
}
125129

126130
startPlayer()
127-
131+
if (player != null) {
132+
mHandler.sendEmptyMessageDelayed(MSG_UPDATE_HUD, 500)
133+
} else {
134+
mHandler.removeMessages(MSG_UPDATE_HUD)
135+
}
128136
//实例化对象并设置监听器
129137
volumeChangeObserver = VolumeChangeObserver(this)
130138
volumeChangeObserver?.setVolumeChangeListener(this)
@@ -557,4 +565,29 @@ class VideoPreviewActivity : VideoBaseActivity(), EventView, TextureView.Surface
557565
player?.setVolume(volume.toFloat(), volume.toFloat())
558566
}
559567
}
568+
569+
private val mHandler: Handler = object : Handler() {
570+
override fun handleMessage(msg: Message) {
571+
when (msg.what) {
572+
MSG_UPDATE_HUD -> {
573+
val videoCachedDuration = player.videoCachedDuration
574+
val audioCachedDuration = player.audioCachedDuration
575+
val videoCachedBytes = player.videoCachedBytes
576+
val audioCachedBytes = player.audioCachedBytes
577+
val tcpSpeed = player.tcpSpeed
578+
579+
tv_a_cache.text = String.format(Locale.US, "%s, %s",
580+
CommonUtils.formatedDurationMilli(audioCachedDuration),
581+
CommonUtils.formatedSize(audioCachedBytes))
582+
tv_v_cache.text = String.format(Locale.US, "%s, %s",
583+
CommonUtils.formatedDurationMilli(videoCachedDuration),
584+
CommonUtils.formatedSize(videoCachedBytes))
585+
tv_tcp_speed.text = String.format(Locale.US, "%s",
586+
CommonUtils.formatedSpeed(tcpSpeed, 1000))
587+
removeMessages(MSG_UPDATE_HUD)
588+
sendEmptyMessageDelayed(MSG_UPDATE_HUD, 500)
589+
}
590+
}
591+
}
592+
}
560593
}

sdkdemo/src/main/res/layout/activity_video_preview.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,15 @@
3636
android:layout_marginEnd="16dp"
3737
android:layout_marginBottom="10dp">
3838

39+
<include
40+
android:id="@+id/ll_dash_board"
41+
android:layout_height="wrap_content"
42+
android:layout_width="200dp"
43+
app:layout_constraintTop_toTopOf="parent"
44+
app:layout_constraintEnd_toEndOf="parent"
45+
app:layout_constraintBottom_toTopOf="@id/iv_orientation"
46+
layout="@layout/dash_board_layout" />
47+
3948
<com.tencent.iot.explorer.link.demo.common.customView.RoundImageView
4049
android:id="@+id/iv_orientation_back"
4150
android:layout_width="32dp"
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="wrap_content"
5+
android:layout_height="wrap_content"
6+
android:background="@android:drawable/screen_background_light_transparent"
7+
android:padding="5dp">
8+
9+
<TextView
10+
android:id="@+id/tv_v_cache_title"
11+
android:layout_width="wrap_content"
12+
android:layout_height="wrap_content"
13+
android:background="@android:color/transparent"
14+
android:text="v_cache: "
15+
android:textColor="@color/red_e54545"
16+
app:layout_constraintStart_toStartOf="parent"
17+
app:layout_constraintTop_toTopOf="parent" />
18+
19+
<TextView
20+
android:id="@+id/tv_v_cache"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:background="@android:color/transparent"
24+
android:text="v_cache"
25+
android:textColor="@color/red_e54545"
26+
app:layout_constraintBottom_toBottomOf="@id/tv_v_cache_title"
27+
app:layout_constraintStart_toEndOf="@id/tv_v_cache_title"
28+
app:layout_constraintTop_toTopOf="@id/tv_v_cache_title" />
29+
30+
<TextView
31+
android:id="@+id/tv_a_cache_title"
32+
android:layout_width="wrap_content"
33+
android:layout_height="wrap_content"
34+
android:background="@android:color/transparent"
35+
android:text="a_cache: "
36+
android:textColor="@color/red_e54545"
37+
app:layout_constraintStart_toStartOf="parent"
38+
app:layout_constraintTop_toBottomOf="@id/tv_v_cache_title" />
39+
40+
<TextView
41+
android:id="@+id/tv_a_cache"
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:background="@android:color/transparent"
45+
android:text="a_cache"
46+
android:textColor="@color/red_e54545"
47+
app:layout_constraintBottom_toBottomOf="@id/tv_a_cache_title"
48+
app:layout_constraintStart_toEndOf="@id/tv_a_cache_title"
49+
app:layout_constraintTop_toTopOf="@id/tv_a_cache_title" />
50+
51+
<TextView
52+
android:id="@+id/tv_tcp_speed_title"
53+
android:layout_width="wrap_content"
54+
android:layout_height="wrap_content"
55+
android:background="@android:color/transparent"
56+
android:text="speed: "
57+
android:textColor="@color/red_e54545"
58+
app:layout_constraintStart_toStartOf="parent"
59+
app:layout_constraintTop_toBottomOf="@id/tv_a_cache_title" />
60+
61+
<TextView
62+
android:id="@+id/tv_tcp_speed"
63+
android:layout_width="wrap_content"
64+
android:layout_height="wrap_content"
65+
android:background="@android:color/transparent"
66+
android:text="speed"
67+
android:textColor="@color/red_e54545"
68+
app:layout_constraintBottom_toBottomOf="@id/tv_tcp_speed_title"
69+
app:layout_constraintStart_toEndOf="@id/tv_tcp_speed_title"
70+
app:layout_constraintTop_toTopOf="@id/tv_tcp_speed_title" />
71+
</androidx.constraintlayout.widget.ConstraintLayout>

0 commit comments

Comments
 (0)