desc:获取rtsp推流地址

main
xiaowusky 2 years ago
parent 8c107e5711
commit 76a09ce971

@ -0,0 +1,5 @@
package com.yinuo.safetywatcher.watcher.bean
import com.common.commonlib.net.bean.BaseResponse
data class GetRtspUrlResponse(val data: String = "") : BaseResponse()

@ -3,6 +3,8 @@ package com.yinuo.safetywatcher.watcher.net
import com.common.commonlib.net.BaseObserve
import com.common.commonlib.net.bean.BaseResponse
import com.common.commonlib.net.callback.RequestNoResultCallBack
import com.common.commonlib.net.callback.RequestResultCallBack
import com.yinuo.safetywatcher.watcher.bean.GetRtspUrlResponse
import io.reactivex.rxjava3.core.Observable
import retrofit2.http.GET
import retrofit2.http.Headers
@ -11,7 +13,7 @@ import retrofit2.http.Query
/**
* 心跳
*/
class HeartbeatApi : BaseObserve<HeartbeatApi.Api>(Api::class.java) {
class DevicesApi : BaseObserve<DevicesApi.Api>(Api::class.java) {
fun heartBeat(sn: String) {
observe(api.heartBeat(sn), object : RequestNoResultCallBack<BaseResponse>() {
@ -23,10 +25,19 @@ class HeartbeatApi : BaseObserve<HeartbeatApi.Api>(Api::class.java) {
})
}
fun getPushUrl(sn: String, callBack: RequestResultCallBack<GetRtspUrlResponse>) {
observe(api.getPushUrl(sn), callBack)
}
interface Api {
@Headers("baseurl:host")
@GET("/api/device/refresh")
fun heartBeat(@Query("deviceSn") sn: String): Observable<BaseResponse>
@Headers("baseurl:host")
@GET("/api/device/getRtspUrl")
fun getPushUrl(@Query("deviceSn") sn: String): Observable<GetRtspUrlResponse>
}
}

@ -24,16 +24,15 @@ const val FORM_DATA = "multipart/form-data";
*/
class UploadFileApi : BaseObserve<UploadFileApi.Api>(Api::class.java) {
open fun singleUpload(path: String, videoTime: Long) {
open fun singleUpload(
path: String,
videoTime: Long,
callBack: RequestResultCallBack<BaseResponse>
) {
observe(
api.singleUpload(makeParamsMaps(videoTime), makeFileBodyPart(path)),
object : RequestResultCallBack<BaseResponse>() {
override fun onResult(result: BaseResponse) {
}
override fun onError(error: String?) {
}
})
callBack
)
}
interface Api {

@ -4,7 +4,9 @@ import android.annotation.SuppressLint
import android.app.IntentService
import android.content.Context
import android.content.Intent
import com.yinuo.safetywatcher.watcher.net.HeartbeatApi
import com.common.commonlib.net.callback.RequestResultCallBack
import com.yinuo.safetywatcher.watcher.bean.GetRtspUrlResponse
import com.yinuo.safetywatcher.watcher.net.DevicesApi
import com.yinuo.safetywatcher.watcher.utils.LztekUtil
@ -15,8 +17,8 @@ private const val ACTION_START = "com.yinuo.safetywatcher.watcher.services.actio
*/
class HeartbeatService : IntentService("HeartbeatService") {
private val heartbeatApi by lazy {
HeartbeatApi()
private val devicesApi by lazy {
DevicesApi()
}
override fun onHandleIntent(intent: Intent?) {
@ -29,14 +31,30 @@ class HeartbeatService : IntentService("HeartbeatService") {
@SuppressLint("HardwareIds")
private fun handleActionStart(intent: Intent) {
heartbeatApi.heartBeat(LztekUtil.getSn())
devicesApi.heartBeat(LztekUtil.getSn())
checkAndGetRtspUrl()
Thread.sleep(30000)
handleActionStart(intent)
}
private fun checkAndGetRtspUrl() {
if (LztekUtil.getRtspUrl().isNullOrEmpty()) {
devicesApi.getPushUrl(
LztekUtil.getSn(),
object : RequestResultCallBack<GetRtspUrlResponse>() {
override fun onResult(result: GetRtspUrlResponse) {
LztekUtil.setRtspUrl(result.data)
}
override fun onError(error: String?) {
}
})
}
}
companion object {
@JvmStatic
fun startActionStart(context: Context) {
fun actionStart(context: Context) {
val intent = Intent(context, HeartbeatService::class.java).apply {
action = ACTION_START
}

@ -1,6 +1,8 @@
package com.yinuo.safetywatcher.watcher.ui
import android.view.View
import com.common.commonlib.net.bean.BaseResponse
import com.common.commonlib.net.callback.RequestResultCallBack
import com.yinuo.safetywatcher.R
import com.yinuo.safetywatcher.databinding.ActivityCloudBinding
import com.yinuo.safetywatcher.watcher.base.NoOptionsActivity
@ -29,7 +31,14 @@ class CloudActivity : NoOptionsActivity() {
syncSensor.setOnClickListener { }
syncVedio.setOnClickListener {
val path = PathUtils.getExternalStorageDirectory() + "/test2.mp4"
uploadApi.singleUpload(path, System.currentTimeMillis())
uploadApi.singleUpload(path, System.currentTimeMillis(), object :
RequestResultCallBack<BaseResponse>() {
override fun onResult(result: BaseResponse) {
}
override fun onError(error: String?) {
}
})
}
syncOnce.setOnClickListener { }
}

@ -28,7 +28,7 @@ class HomeActivity : NoOptionsActivity() {
@RequiresApi(Build.VERSION_CODES.R)
override fun initView() {
initTopbarHelper()
HeartbeatService.startActionStart(this@HomeActivity)
HeartbeatService.actionStart(this@HomeActivity)
mBinding.apply {
itemSetting.setOnClickListener {
startActivity(Intent(this@HomeActivity, SettingActivity::class.java))

@ -6,9 +6,11 @@ import java.security.MessageDigest
object LztekUtil {
private var mLztek: Lztek? = null;
private var mLztek: Lztek? = null
private var sn: String? = null;
private var sn: String? = null
private var rtspUrl: String = ""
fun setObject(value: Lztek) {
mLztek = value
@ -20,7 +22,7 @@ object LztekUtil {
fun getSn(): String {
if (sn == null) {
val mac = LztekUtil.getLztek().ethMac ?: "unKnow"
val mac = getLztek().ethMac ?: "unKnow"
val md = MessageDigest.getInstance("MD5") // 生成一个MD5加密计算摘要
md.update(mac.toByteArray()) // 计算md5函数
/**
@ -39,4 +41,12 @@ object LztekUtil {
}
return sn!!
}
fun getRtspUrl(): String {
return rtspUrl
}
fun setRtspUrl(str: String) {
this.rtspUrl = str
}
}
Loading…
Cancel
Save