package com.dlc.eboard.ui.monitor

import android.os.Bundle
import cn.nodemedia.NodePlayer
import cn.nodemedia.NodePlayerView
import com.dlc.eboard.databinding.ActivityMonitorFullScreenBinding
import com.rc.core.ui.activity.RcBaseActivity
import com.rc.httpcore.vo.response.MonitorVo

/**
 * 视频监控-全屏
 *
 * @author ReiChin_
 */
class MonitorFullScreenActivity: RcBaseActivity<ActivityMonitorFullScreenBinding>() {

    private lateinit var mMonitorVo: MonitorVo

    private val mNodePlayer by lazy { NodePlayer(this) }

    override fun createViewBinding() = ActivityMonitorFullScreenBinding.inflate(layoutInflater)

    override fun initViews(savedInstanceState: Bundle?) {
        mMonitorVo = intent.getParcelableExtra("data")!!

        viewBinding.fullScreen.setOnClickListener { finish() }

        initMonitor()
    }

    private fun initMonitor() {
        // 设置渲染器类型
        viewBinding.monitor.renderType = NodePlayerView.RenderType.SURFACEVIEW
        // 设置视频画面缩放模式
        viewBinding.monitor.setUIViewContentMode(NodePlayerView.UIViewContentMode.ScaleToFill)

        // 设置播放视图
        mNodePlayer.setPlayerView(viewBinding.monitor)
        // 设置RTSP流使用的传输协议,支持的模式有:
        mNodePlayer.setRtspTransport(NodePlayer.RTSP_TRANSPORT_TCP)
        mNodePlayer.setInputUrl(mMonitorVo.fmp4)
//        mNodePlayer.setInputUrl("rtsp://192.168.1.10:554/user=admin_password=nTBCS19C_channel=1_stream=0.sdp?real_stream")
        // 设置视频是否开启
        mNodePlayer.setVideoEnable(true)
        mNodePlayer.setBufferTime(0)
        mNodePlayer.setMaxBufferTime(0)
        mNodePlayer.start()
    }

    override fun onDestroy() {
        mNodePlayer.stop()
        mNodePlayer.release()
        super.onDestroy()
    }

}