Skip to content

Commit

Permalink
增加TEST INPUT 页面
Browse files Browse the repository at this point in the history
  • Loading branch information
neilyhe committed Feb 11, 2025
1 parent d5c5b58 commit a3129e2
Show file tree
Hide file tree
Showing 8 changed files with 457 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ object VideoConst {
const val VIDEO_WLAN_TIMEOUT_MS = "timeoutMs"
const val VIDEO_WLAN_PARAMS = "params"
const val VIDEO_WLAN_DEV_NAMES = "deviceName"
const val MULTI_VIDEO_P2P_INFO = "p2pInfo"
}
1 change: 1 addition & 0 deletions sdkdemo/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
<activity android:name=".video.VideoInputAuthorizeActivity" />
<activity android:name=".video.VideoWlanDetectActivity" />
<activity android:name=".video.preview.VideoTestActivity" />
<activity android:name=".video.VideoTestInputActivity" />
<activity android:name=".video.preview.WlanVideoPreviewActivity"
android:configChanges="orientation|keyboardHidden|screenSize"/>
<activity android:name=".video.VideoMainActivity" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class VideoOptionsActivity : VideoBaseActivity() {
override fun setListener() {
btn_video.setOnClickListener { jumpActivity(VideoInputAuthorizeActivity::class.java) }
btn_video_wlan.setOnClickListener { jumpActivity(VideoWlanDetectActivity::class.java) }
btn_video_test.setOnClickListener { jumpActivity(VideoTestActivity::class.java) }
btn_video_test.setOnClickListener { jumpActivity(VideoTestInputActivity::class.java) }
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.tencent.iot.explorer.link.demo.video

import android.content.Intent
import android.os.Bundle
import android.text.InputType
import android.view.View
import com.tencent.iot.explorer.link.core.utils.SharePreferenceUtil
import com.tencent.iot.explorer.link.demo.R
import com.tencent.iot.explorer.link.demo.VideoBaseActivity
import com.tencent.iot.explorer.link.demo.video.preview.VideoTestActivity
import com.tencent.iot.video.link.consts.VideoConst
import kotlinx.android.synthetic.main.activity_video_input_authorize.btn_login
import kotlinx.android.synthetic.main.activity_video_input_authorize.product_id_layout
import kotlinx.android.synthetic.main.activity_video_test_input.device_name_layout
import kotlinx.android.synthetic.main.activity_video_test_input.p2p_info_layout
import kotlinx.android.synthetic.main.blue_title_layout.iv_back
import kotlinx.android.synthetic.main.blue_title_layout.tv_title
import kotlinx.android.synthetic.main.input_item_layout.view.ev_content
import kotlinx.android.synthetic.main.input_item_layout.view.tv_tip
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.MainScope

class VideoTestInputActivity : VideoBaseActivity(), CoroutineScope by MainScope() {

override fun getContentView(): Int {
return R.layout.activity_video_test_input
}

override fun initView() {
val productId = SharePreferenceUtil.getString(
this@VideoTestInputActivity,
VideoConst.VIDEO_CONFIG,
VideoConst.MULTI_VIDEO_PROD_ID
)
val deviceName = SharePreferenceUtil.getString(
this@VideoTestInputActivity,
VideoConst.VIDEO_CONFIG,
VideoConst.VIDEO_WLAN_DEV_NAMES
)
val p2pInfo = SharePreferenceUtil.getString(
this@VideoTestInputActivity,
VideoConst.VIDEO_CONFIG,
VideoConst.MULTI_VIDEO_P2P_INFO
)
tv_title.setText(R.string.iot_test_demo_name)
product_id_layout.tv_tip.setText(R.string.product_id)
device_name_layout.tv_tip.setText(R.string.device_name)
p2p_info_layout.tv_tip.setText(R.string.p2p_info)
if (productId.isNotEmpty()) {
product_id_layout.ev_content.setText(productId)
}
product_id_layout.ev_content.setHint(R.string.hint_product_id)
product_id_layout.ev_content.inputType = InputType.TYPE_CLASS_TEXT
if (deviceName.isNotEmpty()) {
device_name_layout.ev_content.setText(deviceName)
}
device_name_layout.ev_content.setHint(R.string.hint_device_name)
device_name_layout.ev_content.inputType = InputType.TYPE_CLASS_TEXT
if (p2pInfo.isNotEmpty()) {
p2p_info_layout.ev_content.setText(p2pInfo)
}
p2p_info_layout.ev_content.setHint(R.string.hint_p2p_info)
p2p_info_layout.ev_content.inputType = InputType.TYPE_CLASS_TEXT
}

override fun setListener() {
iv_back.setOnClickListener { finish() }
btn_login.setOnClickListener(loginClickedListener)
}

var loginClickedListener = object : View.OnClickListener {
override fun onClick(v: View?) {
if (product_id_layout.ev_content.text.isNullOrEmpty()) {
show(getString(R.string.hint_product_id))
return
}
SharePreferenceUtil.saveString(
this@VideoTestInputActivity,
VideoConst.VIDEO_CONFIG,
VideoConst.MULTI_VIDEO_PROD_ID,
product_id_layout.ev_content.text.toString()
)
if (device_name_layout.ev_content.text.isNullOrEmpty()) {
show(getString(R.string.hint_device_name))
return
}
SharePreferenceUtil.saveString(
this@VideoTestInputActivity,
VideoConst.VIDEO_CONFIG,
VideoConst.VIDEO_WLAN_DEV_NAMES,
device_name_layout.ev_content.text.toString()
)
if (p2p_info_layout.ev_content.text.isNullOrEmpty()) {
show(getString(R.string.hint_p2p_info))
return
}
SharePreferenceUtil.saveString(
this@VideoTestInputActivity,
VideoConst.VIDEO_CONFIG,
VideoConst.MULTI_VIDEO_P2P_INFO,
p2p_info_layout.ev_content.text.toString()
)
val intent = Intent(this@VideoTestInputActivity, VideoTestActivity::class.java)
intent.putExtra("productId", product_id_layout.ev_content.text.toString())
intent.putExtra("deviceName", device_name_layout.ev_content.text.toString())
intent.putExtra("p2pInfo", p2p_info_layout.ev_content.text.toString())
val bundle = Bundle()
intent.putExtra(VideoConst.VIDEO_CONFIG, bundle)
startActivity(intent)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.tencent.iot.explorer.link.demo.video.preview

import android.Manifest
import android.graphics.SurfaceTexture
import android.media.AudioFormat
import android.os.Bundle
import android.os.Handler
import android.os.Message
Expand All @@ -9,23 +11,35 @@ import android.util.DisplayMetrics
import android.util.Log
import android.view.Surface
import android.view.TextureView
import android.view.View
import android.view.WindowManager
import android.widget.Toast
import com.alibaba.fastjson.JSONArray
import com.tencent.iot.explorer.link.demo.App
import com.tencent.iot.explorer.link.demo.R
import com.tencent.iot.explorer.link.demo.VideoBaseActivity
import com.tencent.iot.explorer.link.demo.common.log.L
import com.tencent.iot.explorer.link.demo.common.util.CommonUtils
import com.tencent.iot.explorer.link.demo.common.util.ImageSelect
import com.tencent.iot.explorer.link.demo.video.Command
import com.tencent.iot.explorer.link.demo.video.DevInfo
import com.tencent.iot.explorer.link.demo.video.playback.VideoPlaybackActivity
import com.tencent.iot.explorer.link.demo.video.utils.TipToastDialog
import com.tencent.iot.explorer.link.demo.video.utils.ToastDialog
import com.tencent.iot.video.link.util.audio.AudioRecordUtil
import com.tencent.xnet.XP2P
import com.tencent.xnet.XP2PCallback
import kotlinx.android.synthetic.main.activity_video_preview.iv_down
import kotlinx.android.synthetic.main.activity_video_preview.iv_left
import kotlinx.android.synthetic.main.activity_video_preview.iv_right
import kotlinx.android.synthetic.main.activity_video_preview.iv_up
import kotlinx.android.synthetic.main.activity_video_preview.layout_video_preview
import kotlinx.android.synthetic.main.activity_video_preview.radio_photo
import kotlinx.android.synthetic.main.activity_video_preview.radio_playback
import kotlinx.android.synthetic.main.activity_video_preview.radio_record
import kotlinx.android.synthetic.main.activity_video_preview.radio_talk
import kotlinx.android.synthetic.main.activity_video_preview.tv_video_quality
import kotlinx.android.synthetic.main.activity_video_preview.v_preview
import kotlinx.android.synthetic.main.activity_video_test.btn_connect
import kotlinx.android.synthetic.main.activity_video_test.et_device_name
import kotlinx.android.synthetic.main.activity_video_test.et_p2p_info
import kotlinx.android.synthetic.main.activity_video_test.et_product_id
import kotlinx.android.synthetic.main.dash_board_layout.tv_a_cache
import kotlinx.android.synthetic.main.dash_board_layout.tv_tcp_speed
import kotlinx.android.synthetic.main.dash_board_layout.tv_v_cache
Expand Down Expand Up @@ -59,22 +73,46 @@ open class VideoTestActivity : VideoBaseActivity(), XP2PCallback, CoroutineScope
var showTip = false
var firstIn = true
val MSG_UPDATE_HUD = 1
var permissions = arrayOf(Manifest.permission.RECORD_AUDIO)
var filePath: String? = null
var audioRecordUtil: AudioRecordUtil? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
XP2P.setCallback(this)
}
@Volatile
var speakAble = false

override fun getContentView(): Int {
return R.layout.activity_video_test
}

override fun initView() {
productId = intent.getStringExtra("productId")?.toString() ?: ""
deviceName = intent.getStringExtra("deviceName")?.toString() ?: ""
xp2pInfo = intent.getStringExtra("p2pInfo")?.toString() ?: ""
audioRecordUtil = AudioRecordUtil(this, "${productId}/${deviceName}", 16000, AudioFormat.CHANNEL_IN_MONO, AudioFormat.ENCODING_PCM_16BIT)
XP2P.setCallback(this)
XP2P.startService(this, "${productId}/${deviceName}", productId, deviceName)

val ret = XP2P.setParamsForXp2pInfo(
"${productId}/${deviceName}", "", "", xp2pInfo
)
if (ret != 0) {
launch(Dispatchers.Main) {
val errInfo: String
if (ret.toString() == "-1007") {
errInfo = getString(R.string.xp2p_err_version)
} else {
errInfo = getString(
R.string.error_with_code,
"${productId}/${deviceName}",
ret.toString()
)
}
Toast.makeText(this@VideoTestActivity, errInfo, Toast.LENGTH_SHORT).show()
}
}

tv_video_quality.text = "高清"
v_preview.surfaceTextureListener = this
et_product_id.setText(productId)
et_device_name.setText(deviceName)
et_p2p_info.setText(xp2pInfo)
val wm = this.getSystemService(WINDOW_SERVICE) as WindowManager
val dm = DisplayMetrics()
wm.defaultDisplay.getMetrics(dm)
Expand All @@ -86,44 +124,117 @@ open class VideoTestActivity : VideoBaseActivity(), XP2PCallback, CoroutineScope
}

override fun setListener() {
btn_connect.setOnClickListener {
if (et_product_id.text.isNullOrEmpty()) {
show("请输入productId")
return@setOnClickListener
radio_talk.setOnCheckedChangeListener { buttonView, isChecked ->
if (isChecked && checkPermissions(permissions)) {
if (!speakAble(true)) radio_talk.isChecked = false
} else if (isChecked && !checkPermissions(permissions)) {
requestPermission(permissions)
} else {
speakAble(false)
}
if (et_device_name.text.isNullOrEmpty()) {
show("请输入deviceName")
return@setOnClickListener
}
radio_record.setOnCheckedChangeListener { buttonView, isChecked ->
if (isChecked) {
filePath = CommonUtils.generateFileDefaultPath()
var ret = player.startRecord(filePath)
if (ret != 0) {
ToastDialog(
this,
ToastDialog.Type.WARNING,
getString(R.string.record_failed),
2000
).show()
radio_record.isChecked = false
}
} else {
player.stopRecord()
CommonUtils.refreshVideoList(this@VideoTestActivity, filePath)
}
if (et_p2p_info.text.isNullOrEmpty()) {
show("请输入P2PInfo")
return@setOnClickListener
}
radio_playback.setOnClickListener {
val dev = DevInfo()
dev.DeviceName = deviceName
VideoPlaybackActivity.startPlaybackActivity(this@VideoTestActivity, dev)
}
radio_photo.setOnClickListener {
val bitmap = v_preview.getBitmap(player.videoWidth, player.videoHeight)
ImageSelect.saveBitmap(this@VideoTestActivity, bitmap)
ToastDialog(
this,
ToastDialog.Type.SUCCESS,
getString(R.string.capture_successed),
2000
).show()
}
iv_up.setOnClickListener(controlListener)
iv_down.setOnClickListener(controlListener)
iv_right.setOnClickListener(controlListener)
iv_left.setOnClickListener(controlListener)
}

open var controlListener = object : View.OnClickListener {
override fun onClick(v: View?) {
var command = ""
when (v) {
iv_up -> command = Command.getPtzUpCommand(0)
iv_down -> command = Command.getPtzDownCommand(0)
iv_right -> command = Command.getPtzRightCommand(0)
iv_left -> command = Command.getPtzLeftCommand(0)
}
productId = et_product_id.text.toString()
deviceName = et_device_name.text.toString()
xp2pInfo = et_p2p_info.text.toString()
XP2P.startService(
this@VideoTestActivity, "${productId}/${deviceName}", productId, deviceName
)
val ret = XP2P.setParamsForXp2pInfo(
"${productId}/${deviceName}", "", "", xp2pInfo
)
if (ret != 0) {

Thread(Runnable {
if (command.length <= 0) return@Runnable
var retContent = XP2P.postCommandRequestSync(
"${productId}/${deviceName}",
command.toByteArray(), command.toByteArray().size.toLong(), 2 * 1000 * 1000
) ?: ""
launch(Dispatchers.Main) {
val errInfo: String
if (ret.toString() == "-1007") {
errInfo = getString(R.string.xp2p_err_version)
} else {
errInfo = getString(
R.string.error_with_code,
"${productId}/${deviceName}",
ret.toString()
)
if (TextUtils.isEmpty(retContent)) {
retContent = getString(R.string.command_with_error, command)
}
Toast.makeText(this@VideoTestActivity, errInfo, Toast.LENGTH_SHORT).show()
Toast.makeText(this@VideoTestActivity, retContent, Toast.LENGTH_SHORT).show()
}
}).start()
}
}

open fun speakAble(able: Boolean): Boolean {
if (able) {
val command = Command.getNvrIpcStatus(0, 0)
val repStatus = XP2P.postCommandRequestSync(
"${productId}/${deviceName}",
command.toByteArray(), command.toByteArray().size.toLong(), 2 * 1000 * 1000
) ?: ""

launch(Dispatchers.Main) {
var retContent = StringBuilder(repStatus).toString()
if (TextUtils.isEmpty(retContent)) {
retContent = getString(R.string.command_with_error, command)
}
Toast.makeText(this@VideoTestActivity, retContent, Toast.LENGTH_SHORT).show()
}

JSONArray.parseArray(repStatus, DevStatus::class.java)?.let {
if (it.size == 1 && it.get(0).status == 0) {
XP2P.runSendService(
"${productId}/${deviceName}",
Command.getTwoWayRadio(0),
true
)
audioRecordUtil?.start()
speakAble = true
return true
}
}

} else {
speakAble = false
audioRecordUtil?.stop()
XP2P.stopSendService("${productId}/${deviceName}", null)
return true
}
speakAble = false
return false
}

private fun resetPlayer() {
Expand Down
Loading

0 comments on commit a3129e2

Please sign in to comment.