[6.8.0][驾驶位视频流] 代码提交
This commit is contained in:
@@ -57,6 +57,8 @@ import com.zhjt.mogo_core_function_devatools.badcase.consts.BadCaseConfig
|
||||
import com.zhjt.mogo_core_function_devatools.binding.BindingCarManager
|
||||
import com.zhjt.mogo_core_function_devatools.block.MoGoBlockProviderImpl
|
||||
import com.zhjt.mogo_core_function_devatools.coldstart.ColdStartManager
|
||||
import com.zhjt.mogo_core_function_devatools.driver.video.DriveSeatVideoProviderImpl
|
||||
import com.mogo.eagle.core.function.api.driver.video.IDriveSeatVideoProvider
|
||||
import com.zhjt.mogo_core_function_devatools.env.EnvChangeManager
|
||||
import com.zhjt.mogo_core_function_devatools.exam.ExamControlManager
|
||||
import com.zhjt.mogo_core_function_devatools.funcconfig.FuncConfigCenter.Companion.bizConfigCenter
|
||||
@@ -125,6 +127,8 @@ class DevaToolsProvider : IDevaToolsProvider, IAppStateListener {
|
||||
ARouter.getInstance().build(MogoServicePaths.PATH_MAP_ROUTE_GUIDE).navigation() as? IMapRouteProvider
|
||||
}
|
||||
|
||||
private val driveSeatVideoProvider by lazy { DriveSeatVideoProviderImpl() }
|
||||
|
||||
@Volatile
|
||||
private var lastCanAutopilotStatus: Int? = null
|
||||
|
||||
@@ -682,4 +686,8 @@ class DevaToolsProvider : IDevaToolsProvider, IAppStateListener {
|
||||
override fun takeOver(@TakeOverAnnotation takeOverAnnotation: Int) {
|
||||
TakeOverManager.takeOverManager.takeOver(takeOverAnnotation)
|
||||
}
|
||||
|
||||
override fun driveSeatVideoProvider(): IDriveSeatVideoProvider {
|
||||
return driveSeatVideoProvider
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,155 @@
|
||||
package com.zhjt.mogo_core_function_devatools.driver.video
|
||||
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import androidx.core.view.doOnAttach
|
||||
import androidx.core.view.doOnDetach
|
||||
import com.mogo.commons.constants.HostConst
|
||||
import com.mogo.eagle.core.data.BaseResponse
|
||||
import com.mogo.eagle.core.data.app.AppConfigInfo
|
||||
import com.mogo.eagle.core.function.api.driver.video.IDriveSeatVideoProvider
|
||||
import com.mogo.eagle.core.function.api.driver.video.IDriveSeatVideoProvider.Event
|
||||
import com.mogo.eagle.core.function.api.driver.video.IDriveSeatVideoProvider.Event.Failed
|
||||
import com.mogo.eagle.core.function.api.driver.video.IDriveSeatVideoProvider.Event.Loading
|
||||
import com.mogo.eagle.core.function.api.driver.video.IDriveSeatVideoProvider.Event.Playing
|
||||
import com.mogo.eagle.core.network.MoGoRetrofitFactory
|
||||
import com.mogo.eagle.core.utilcode.util.AppStateManager
|
||||
import com.tencent.liteav.basic.log.TXCLog
|
||||
import com.tencent.rtmp.ITXLivePlayListener
|
||||
import com.tencent.rtmp.TXLiveConstants
|
||||
import com.tencent.rtmp.TXLivePlayConfig
|
||||
import com.tencent.rtmp.TXLivePlayer
|
||||
import com.tencent.rtmp.ui.TXCloudVideoView
|
||||
import com.zhjt.mogo_core_function_devatools.driver.video.vo.VideoUrlData
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import retrofit2.http.GET
|
||||
import retrofit2.http.Headers
|
||||
import retrofit2.http.Query
|
||||
import java.lang.ref.WeakReference
|
||||
|
||||
class DriveSeatVideoProviderImpl: IDriveSeatVideoProvider {
|
||||
|
||||
companion object {
|
||||
private const val TAG = "DriveSeatVideoProvider"
|
||||
}
|
||||
|
||||
@Volatile
|
||||
private var target: WeakReference<TXCloudVideoView>? = null
|
||||
|
||||
@Volatile
|
||||
private var timer: Job? = null
|
||||
|
||||
private val scope by lazy { CoroutineScope(Dispatchers.IO + SupervisorJob()) }
|
||||
|
||||
private var data: VideoUrlData? = null
|
||||
|
||||
internal interface IVideoLiveUrlApi {
|
||||
@Headers("Content-Type:application/json;charset=UTF-8")
|
||||
@GET("/eagleEye-mis/camera/monitor/watch/status")
|
||||
suspend fun requestVideoLiveUrl(@Query(value = "numberPlate") numberPlate: String, @Query("cameraType") cameraType: Int, @Query("protocolType") protocolType: Int): BaseResponse<VideoUrlData>
|
||||
}
|
||||
|
||||
|
||||
override suspend fun requestVideoInfo(): VideoUrlData? {
|
||||
val plateNumber = AppConfigInfo.plateNumber
|
||||
if (TextUtils.isEmpty(plateNumber)) {
|
||||
Log.e(TAG, "-- isVideoLiveUsable -- plate number is empty.")
|
||||
return null
|
||||
}
|
||||
val resp = getApi()?.requestVideoLiveUrl(plateNumber, 2, 2) ?: return null
|
||||
Log.e(TAG, "-- isVideoLiveUsable -- receive response: {code: ${resp.code}, msg: ${resp.msg}, result: ${resp.result}}")
|
||||
data = resp.result
|
||||
return resp.result
|
||||
}
|
||||
|
||||
override fun getDriveVideoView(playUrl: String, playCallback: ((Event) -> Unit)?): View? {
|
||||
val activity = AppStateManager.currentActivity() ?: return null
|
||||
val t = target?.get()
|
||||
if (t != null) {
|
||||
return t
|
||||
}
|
||||
val x = TXCloudVideoView(activity)
|
||||
Log.d(TAG, "getDriveVideoView --> $playUrl")
|
||||
x.doOnAttach {
|
||||
Log.d(TAG, "onAttachToWindow --> $playUrl")
|
||||
val player = TXLivePlayer(activity)
|
||||
player.setPlayerView(x)
|
||||
player.setMute(true)
|
||||
TXCLog.setLevel(4)
|
||||
val config = TXLivePlayConfig()
|
||||
config.setConnectRetryCount(30)
|
||||
player.setConfig(config)
|
||||
player.enableHardwareDecode(true)
|
||||
player.startPlay(playUrl, TXLivePlayer.PLAY_TYPE_LIVE_RTMP)
|
||||
player.setPlayListener(object : ITXLivePlayListener {
|
||||
|
||||
override fun onPlayEvent(event: Int, bundle: Bundle?) {
|
||||
Log.d(TAG, "直播信息 => event: $event, playUrl: $playUrl, bundle: $bundle")
|
||||
if (event == TXLiveConstants.PLAY_EVT_PLAY_LOADING) {
|
||||
Log.d(TAG, "play loading...")
|
||||
playCallback?.invoke(Loading)
|
||||
} else if (event == TXLiveConstants.PLAY_EVT_PLAY_BEGIN) {
|
||||
Log.d(TAG, "play begin...")
|
||||
start()
|
||||
playCallback?.invoke(Playing)
|
||||
} else {
|
||||
if (event < 0) {
|
||||
Log.d(TAG, "play failed...$event, bundle: $bundle")
|
||||
stop()
|
||||
playCallback?.invoke(Failed(bundle?.toString() ?: "播放失败"))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onNetStatus(bundle: Bundle?) {
|
||||
Log.d(TAG, "直播信息 => onNetStatus -> $bundle")
|
||||
}
|
||||
})
|
||||
|
||||
x.doOnDetach {
|
||||
Log.d(TAG, "-- onDetachedFromWindow ---: $playUrl")
|
||||
try {
|
||||
player.stopPlay(true)
|
||||
stop()
|
||||
} finally {
|
||||
target?.clear()
|
||||
}
|
||||
}
|
||||
}
|
||||
target = WeakReference(x)
|
||||
return x
|
||||
}
|
||||
|
||||
|
||||
override fun getLastData(): VideoUrlData? {
|
||||
return data
|
||||
}
|
||||
|
||||
private fun start() {
|
||||
timer?.cancel()
|
||||
scope.launch {
|
||||
val result = requestVideoInfo()
|
||||
if (result != null) {
|
||||
data = result
|
||||
}
|
||||
delay(5000)
|
||||
}.also {
|
||||
timer = it
|
||||
}
|
||||
}
|
||||
|
||||
private fun stop() {
|
||||
timer?.cancel()
|
||||
}
|
||||
|
||||
private fun getApi(): IVideoLiveUrlApi? {
|
||||
return MoGoRetrofitFactory.getInstanceNoCallAdapter(HostConst.getHost()).create(IVideoLiveUrlApi::class.java)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user