/// <summary> /// 开启视频预览 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnOk_Click(object sender, EventArgs e) { string terminalId = this.txtTerminalId.Text.Trim(); if (string.IsNullOrEmpty(terminalId)) { errPrv.SetError(this.txtTerminalId, "终端编号不能为空..."); this.txtTerminalId.Focus(); return; } ValueString <AVChannel> selChn = this.cboChn.SelectedItem as ValueString <AVChannel>; if (selChn == null) { errPrv.SetError(this.cboChn, "请选择有效的预览通道..."); this.cboChn.Focus(); return; } string svrIp = this.txtSvrIp.Text.Trim(); if (string.IsNullOrEmpty(svrIp)) { errPrv.SetError(this.txtSvrIp, "视频服务器IP地址不能为空..."); this.txtSvrIp.Focus(); return; } ushort svrPort = (ushort)this.nudPort.Value; this.btnOk.Enabled = false; this.TerminalId = null; var task = Task.Factory.StartNew(() => { var result = UrlApiHelper.ControlVideo(terminalId, selChn.Value, VedioControlType.RealTime); if (result == null) { GuiHelper.MsgBox("服务器连接异常..."); } else if (result.Status != 0) { GuiHelper.MsgBox("实时预览开启失败: " + result.Message); } else { this.TerminalId = terminalId; this.Channel = selChn.Value; Settings.Default.DVRSvrIp = svrIp; Settings.Default.DVRSvrPort = svrPort; } }); task.Wait(); this.btnOk.Enabled = true; if (!string.IsNullOrEmpty(this.TerminalId)) { this.DialogResult = DialogResult.OK; this.Close(); } }
/// <summary> /// 停止播放流媒体 /// </summary> public void StopPlay() { this.btnPlay.Enabled = false; if (ChannelId > 0) { if (this.btnRecord.Checked) { // 正在录制则进行停止 LogAppend("正在停止视频录制..."); // 停止录像 this.btnRecord.Checked = false; PlayerMethods.CarEyePlayer_StopManuRecording(ChannelId); LogAppend("视频录制已停止."); } // 预览停止代码 PlayerMethods.CarEyePlayer_CloseStream(ChannelId); UrlApiHelper.ControlVideo(Token.TerminalId, Token.LogicChn, VedioControlType.Stop); ChannelId = -1; } LinkToken(null); mImagePath = null; mVideoPath = null; UpdateDisplayStatus(); }