} //发送视频调阅命令 private void button1_Click(object sender, EventArgs e) { //直接使用流媒体库播放视频 string sid = listBox2.SelectedValue.ToString(); returningValue1 = CMSSdk.VM_CMS_RealPlay(lHandle, pictureBox1.Handle, "ch1"); if (returningValue1 < 0) { MessageBox.Show("预览失败!"); } }
//打开预览 private void button1_Click_1(object sender, EventArgs e) { if (lHandle != -1) { int i = CMSSdk.VM_CMS_RealPlay(lHandle, pictureBox1.Handle, "ch1"); if (i < 0) { MessageBox.Show("视频预览失败!"); } } }
/// <summary> /// 视频预览 /// </summary> /// <param name="strDeviceID"></param> /// <param name="index"></param> /// <returns></returns> public static int Open(string strDeviceID, int index, ref string IP, ref int nChannel, ref int m_lUserID, ref int m_lRealHandle) { if (Form1.videoboxs[index].InvokeRequired) { ControlDelegate d = Open; Form1.videoboxs[index].Invoke(d, strDeviceID, index, IP, nChannel, m_lUserID, m_lRealHandle); } else { Guid DeviceID = new Guid(strDeviceID); Entities.CameraList device = Class1.cameraList.Find( delegate(Entities.CameraList camera) { return(camera.DeviceID.Equals(DeviceID)); } ); if (device == null) { return(-1); } Entities.StreamMediaList streamMedia = Class1.streamMediaList.Find( delegate(Entities.StreamMediaList sm) { return(sm.DeviceID.Equals(device.StreamMedia_DeviceID)); }); if (streamMedia == null) { return(-1); } IP = streamMedia.VideoIP; nChannel = device.VideoChannel; string mediaMedia = System.Configuration.ConfigurationManager.AppSettings["MediaStream"]; if (mediaMedia == "1") { #region 流媒体预览 Entities.StreamServerList server = Class1.streamServerList.Find( delegate(Entities.StreamServerList ss) { return(ss.DeviceID.Equals(streamMedia.StreamServerID)); } ); if (server == null) { return(-1); } //视频预览 VMSdk.VM_CLIENT_CONFIG_VMSTREAMINGSER config = new VMSdk.VM_CLIENT_CONFIG_VMSTREAMINGSER(); config.sSID = device.Stream_MainID.ToString(); config.sDeviceAddress = server.StreamServerIP; if (SearchRealPlayVideo(config.sSID, index)) { //流媒体预览视频 //Form1.hwnd[index] = VMSdk.VM_CLIENT_RealPlay(Form1.videoboxs[index].pictureBox1.Handle.ToInt32(), ref config, (int)VMSdk.VM_CLIENT_DEV_TYPE.VM_CLIENT_DEV_RTSP_VMSTREAMINGSER); Form1.hwnd[index] = CMSSdk.VM_CMS_RealPlay(0, Form1.videoboxs[index].pictureBox1.Handle, config.sSID); //存储视频信息 Form1.SID[index] = config.sSID; } #endregion } else { if (SearchRealPlayVideo2(strDeviceID, index)) { CHCNetSDK.NET_DVR_PREVIEWINFO lpPreviewInfo = new CHCNetSDK.NET_DVR_PREVIEWINFO(); lpPreviewInfo.hPlayWnd = Form1.videoboxs[index].pictureBox1.Handle; //预览窗口 lpPreviewInfo.lChannel = device.VideoChannel; //预te览的设备通道 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; //播放库播放缓冲区最大缓冲帧数 CHCNetSDK.REALDATACALLBACK RealData = new CHCNetSDK.REALDATACALLBACK(RealDataCallBack); //预览实时流回调函数 IntPtr pUser = new IntPtr(); //用户数据 if (streamMedia.VideoIP == null) { return(-1); } if (!RecDll.ManualRec.userIDList.ContainsKey(streamMedia.VideoIP)) { return(-1); } int UserID = RecDll.ManualRec.userIDList[streamMedia.VideoIP]; m_lUserID = UserID; Form1.hwnd[index] = CHCNetSDK.NET_DVR_RealPlay_V40(m_lUserID, ref lpPreviewInfo, null /*RealData*/, pUser); m_lRealHandle = Form1.hwnd[index]; if (Form1.hwnd[index] == -1) { uint temp = CHCNetSDK.NET_DVR_GetLastError(); MessageBox.Show("视频预览失败!"); } else { //Form1.SID[index] = config.sSID; Form1.DeviceIDs[index] = strDeviceID; Form1.videoboxs[index].SetVideoInfo(IP, nChannel, m_lUserID, m_lRealHandle, strDeviceID, device.VideoName); } } } } return(Form1.hwnd[index]); }