Exemplo n.º 1
0
        public bool VideoPlayEx()
        {
            bool bolResule = false;

            currentVideoInfo.VideoLoginStateChangeEvent += VideoLoginStateChanged; //注册事件
            VideoPlayState = Enum_VideoPlayState.Connecting;                       //状态置为连接中
            VideoPlayCallback(new VideoPlayCallbackValue {
                evType = Enum_VideoPlayEventType.LoginStart
            });                                                                                           //开始登陆
            //如果当前未登录,通过登陆状态改变回调触发实时播放
            //如果已经登陆,直接获取登陆句柄进行实时预览
            string Temp_strKey = GetDevListKey(CurrentVideoInfo);

            if (SDK_XMSDK.DeviceLogin(Temp_strKey))
            {
                lLogin = CurrentVideoInfo.LoginHandle;
                Thread t = new Thread(new ThreadStart(VideoRealPlay));
                t.IsBackground = true;
                t.Start();
            }
            return(bolResule);
        }
Exemplo n.º 2
0
        private void VideoRealPlay()
        {
            H264_DVR_CLIENTINFO playstru = new H264_DVR_CLIENTINFO();

            playstru.nChannel       = CurrentCameraInfo.Channel - 1;
            playstru.nStream        = 1;
            playstru.nMode          = 0;
            playstru.hWnd           = intptrPlayMain;
            bolRequestRealVideoFlag = true;
            int Temp_intCount = 0;

            while (bolRequestRealVideoFlag)
            {
                VideoPlayCallback(new VideoPlayCallbackValue {
                    evType = Enum_VideoPlayEventType.RequestConn
                });
                m_iPlayhandle = SDK_XMSDK.H264_DVR_RealPlay(Convert.ToInt32(lLogin), ref playstru);
                if (m_iPlayhandle > 0)
                {
                    CurrentVideoInfo.NetworkState = 1;//在线
                    VideoPlayState = Enum_VideoPlayState.InPlayState;
                    VideoPlayCallback(new VideoPlayCallbackValue {
                        evType = Enum_VideoPlayEventType.VideoPlay
                    });                                                                                          //开始播放
                    bolRequestRealVideoFlag = false;
                    if (CurrentVideoPlaySet.VideoRecordEnable)
                    {
                        XMVideo_VideoRecordStart(CurrentVideoPlaySet.VideoRecordFilePath);
                    }
                }
                else
                {
                    VideoPlayState = Enum_VideoPlayState.NotInPlayState;
                    int intResult = SDK_XMSDK.H264_DVR_GetLastError();
                    //视频播放异常,后期根据 H264_DVR_GetLastError 获取错误码进行操作及 提示
                    switch (intResult)
                    {
                    case (int)SDK_RET_CODE.H264_DVR_NATCONNET_REACHED_MAX:
                        VideoPlayCallback(new VideoPlayCallbackValue {
                            evType = Enum_VideoPlayEventType.ConnNumMax
                        });                                                                                               //达到最大连接数量
                        break;

                    case (int)SDK_RET_CODE.H264_DVR_INVALID_HANDLE:     //句柄错误
                        VideoPlayCallback(new VideoPlayCallbackValue {
                            evType = Enum_VideoPlayEventType.VideoPlayException, EventContent = intResult.ToString() + "句柄错误"
                        });                                                                                                                                                     //视频播放异常
                        //退出,重新登陆
                        //注意: 有可能是后台登陆成功后触发这个错误 重新调用登陆接口打开新线程进行登陆
                        //将重连播放的标签置为Flase 结束前一个登陆线程
                        int Temp_intResult = SDK_XMSDK.H264_DVR_Logout(lLogin);
                        CurrentVideoInfo.LoginHandle = -1;
                        CurrentVideoInfo.LoginState  = 0;
                        SDK_XMSDK.DeviceLogin(CurrentVideoInfo);
                        bolRequestRealVideoFlag = false;
                        break;

                    default:
                        VideoPlayCallback(new VideoPlayCallbackValue {
                            evType = Enum_VideoPlayEventType.VideoPlayException, EventContent = intResult.ToString()
                        });                                                                                                                                            //视频播放异常
                        break;
                    }
                    Thread.Sleep(2000);
                }
                if (Temp_intCount > c_intMaxRealPlayNum || m_iPlayhandle > 0)
                {
                    bolRequestRealVideoFlag = false;
                }
                Temp_intCount++;
            }
        }