private void btnPreview_Click(object sender, EventArgs e) { if (m_lUserID < 0) { MessageBox.Show("Please login the device firstly!"); return; } if (m_lRealHandle < 0) { m_lRealHandle = this.preview.startPreview(m_lUserID, iChannelNum[0]); if (m_lRealHandle < 0) { string str; iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_RealPlay_V40 failed, error code= " + iLastErr; //预览失败,输出错误号 failed to start live view, and output the error code. DebugInfo(str); } else { //预览成功 DebugInfo("NET_DVR_RealPlay_V40 succ!"); btnPreview.Text = "停止预览"; } } else { if (this.preview.stopPreview(m_lRealHandle)) { DebugInfo("NET_DVR_StopRealPlay succ!"); m_lRealHandle = -1; btnPreview.Text = "开始预览"; RealPlayWnd.Invalidate();//刷新窗口 refresh the window } else { string str; iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_StopRealPlay failed, error code= " + iLastErr; DebugInfo(str); } } }
private void btnPreview_Click(object sender, EventArgs e) { if (m_lUserID < 0) { MessageBox.Show("Please login the device firstly!"); return; } if (m_bRecord) { MessageBox.Show("Please stop recording firstly!"); return; } if (m_lRealHandle < 0) { CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO(); lpPreviewInfo.hPlayWnd = RealPlayWnd.Handle; //预览窗口 live view window lpPreviewInfo.lChannel = iChannelNum[(int)iSelIndex]; //预览的设备通道 the device channel number lpPreviewInfo.dwStreamType = 0; //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推 lpPreviewInfo.dwLinkMode = 0; //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP lpPreviewInfo.bBlocked = true; //0- 非阻塞取流,1- 阻塞取流 lpPreviewInfo.dwDisplayBufNum = 15; //播放库显示缓冲区最大帧数 IntPtr pUser = IntPtr.Zero; //用户数据 user data if (comboBoxView.SelectedIndex == 0) { //打开预览 Start live view m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser); } else { lpPreviewInfo.hPlayWnd = IntPtr.Zero; //预览窗口 live view window m_ptrRealHandle = RealPlayWnd.Handle; RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数 real-time stream callback function m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, RealData, pUser); } if (m_lRealHandle < 0) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_RealPlay_V40 failed, error code= " + iLastErr; //预览失败,输出错误号 failed to start live view, and output the error code. DebugInfo(str); return; } else { //预览成功 DebugInfo("NET_DVR_RealPlay_V40 succ!"); btnPreview.Text = "Stop View"; } } else { //停止预览 Stop live view if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_StopRealPlay failed, error code= " + iLastErr; DebugInfo(str); return; } if ((comboBoxView.SelectedIndex == 1) && (m_lPort >= 0)) { if (!PlayCtrl.PlayM4_Stop(m_lPort)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "PlayM4_Stop failed, error code= " + iLastErr; DebugInfo(str); } if (!PlayCtrl.PlayM4_CloseStream(m_lPort)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "PlayM4_CloseStream failed, error code= " + iLastErr; DebugInfo(str); } if (!PlayCtrl.PlayM4_FreePort(m_lPort)) { iLastErr = PlayCtrl.PlayM4_GetLastError(m_lPort); str = "PlayM4_FreePort failed, error code= " + iLastErr; DebugInfo(str); } m_lPort = -1; } DebugInfo("NET_DVR_StopRealPlay succ!"); m_lRealHandle = -1; btnPreview.Text = "Live View"; RealPlayWnd.Invalidate();//刷新窗口 refresh the window } return; }
private void btnPreview_Click(object sender, EventArgs e) { if (_mLUserId < 0) { MessageBox.Show(@"Please login the device firstly!"); return; } if (_mBRecord) { MessageBox.Show(@"Please stop recording firstly!"); return; } if (_mLRealHandle < 0) { var lpPreviewInfo = new ChcNetSdk.NetDvrPreviewinfo { hPlayWnd = RealPlayWnd.Handle, lChannel = _iChannelNum[(int)_iSelIndex], dwStreamType = 0, dwLinkMode = 0, bBlocked = true }; //预览窗口 live view window //预览的设备通道 the device channel number //码流类型:0-主码流,1-子码流,2-码流3,3-码流4,以此类推 //连接方式:0- TCP方式,1- UDP方式,2- 多播方式,3- RTP方式,4-RTP/RTSP,5-RSTP/HTTP //0- 非阻塞取流,1- 阻塞取流 var pUser = IntPtr.Zero;//用户数据 user data if (comboBoxView.SelectedIndex == 0) { //打开预览 Start live view _mLRealHandle = ChcNetSdk.NET_DVR_RealPlay_V40(_mLUserId, ref lpPreviewInfo, null /*RealData*/, pUser); } else { lpPreviewInfo.hPlayWnd = IntPtr.Zero; //预览窗口 live view window _mPtrRealHandle = RealPlayWnd.Handle; _realData = RealDataCallBack; //预览实时流回调函数 real-time stream callback function _mLRealHandle = ChcNetSdk.NET_DVR_RealPlay_V40(_mLUserId, ref lpPreviewInfo, _realData, pUser); } if (_mLRealHandle < 0) { _iLastErr = ChcNetSdk.NET_DVR_GetLastError(); _str = "NET_DVR_RealPlay_V40 failed, error code= " + _iLastErr; //预览失败,输出错误号 failed to start live view, and output the error code. DebugInfo(_str); } else { //预览成功 DebugInfo("NET_DVR_RealPlay_V40 succ!"); btnPreview.Text = @"Stop View"; } } else { //停止预览 Stop live view if (!ChcNetSdk.NET_DVR_StopRealPlay(_mLRealHandle)) { _iLastErr = ChcNetSdk.NET_DVR_GetLastError(); _str = "NET_DVR_StopRealPlay failed, error code= " + _iLastErr; DebugInfo(_str); return; } if ((comboBoxView.SelectedIndex == 1) && (_mLPort >= 0)) { if (!PlayCtrl.PlayM4_Stop(_mLPort)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_Stop failed, error code= " + _iLastErr; DebugInfo(_str); } if (!PlayCtrl.PlayM4_CloseStream(_mLPort)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_CloseStream failed, error code= " + _iLastErr; DebugInfo(_str); } if (!PlayCtrl.PlayM4_FreePort(_mLPort)) { _iLastErr = PlayCtrl.PlayM4_GetLastError(_mLPort); _str = "PlayM4_FreePort failed, error code= " + _iLastErr; DebugInfo(_str); } _mLPort = -1; } DebugInfo("NET_DVR_StopRealPlay succ!"); _mLRealHandle = -1; btnPreview.Text = @"Live View"; RealPlayWnd.Invalidate();//刷新窗口 refresh the window } }
private void btnPreview_Click(object sender, EventArgs e) { if (m_lUserID < 0) { MessageBox.Show("Please login the device firstly!"); return; } if (m_bRecord) { MessageBox.Show("Please stop recording firstly!"); return; } if (m_lRealHandle < 0) { CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO(); lpPreviewInfo.hPlayWnd = RealPlayWnd.Handle; lpPreviewInfo.lChannel = iChannelNum[(int)iSelIndex]; lpPreviewInfo.dwStreamType = 0; lpPreviewInfo.dwLinkMode = 0; lpPreviewInfo.bBlocked = true; lpPreviewInfo.dwDisplayBufNum = 15; IntPtr pUser = IntPtr.Zero; m_lRealHandle = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser); if (m_lRealHandle < 0) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_RealPlay_V40 failed, error code= " + iLastErr; DebugInfo(str); return; } else { DebugInfo("NET_DVR_RealPlay_V40 succ!"); btnPreview.Text = "Stop View"; } } else { if (!CHCNetSDK.NET_DVR_StopRealPlay(m_lRealHandle)) { iLastErr = CHCNetSDK.NET_DVR_GetLastError(); str = "NET_DVR_StopRealPlay failed, error code= " + iLastErr; DebugInfo(str); return; } DebugInfo("NET_DVR_StopRealPlay succ!"); m_lRealHandle = -1; btnPreview.Text = "Live View"; RealPlayWnd.Invalidate(); } return; }