Example #1
0
        /// <summary>
        /// 初始化播放
        /// </summary>
        private void InitPlay()
        {
            try
            {
                // 初始化窗体大小样式等
                if (File.Exists(sizeConfig))
                {
                    var txt     = File.ReadAllText(sizeConfig);
                    var content = txt.Split('\n');
                    foreach (var item in content)
                    {
                        var command = item.Split('=');
                        var value   = command[1].Trim();
                        switch (command[0].ToLower())
                        {
                        case "width":
                            Width = int.Parse(value);
                            break;

                        case "height":
                            Height = int.Parse(value);
                            break;

                        default:
                            break;
                        }
                    }
                }
                // 初始化布局、播放资源等
                if (File.Exists(basePlayPath))
                {
                    var txt = File.ReadAllText(basePlayPath);

                    var commands    = txt.Split('|');
                    var commandName = commands[0];
                    var paramStr    = commands[1];

                    switch (commandName.ToUpper())
                    {
                    case "PLAYPANEL":
                        TvConfig tvConfig = JsonConvert.DeserializeObject <TvConfig>(paramStr);
                        PlayOnTV(tvConfig);
                        break;

                    default:
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Default.Error("初始化播放错误", e);
            }
        }
Example #2
0
        /// <summary>
        /// 播放命令操作
        /// </summary>
        /// <param name="tvConfig"></param>
        public void PlayOnTV(TvConfig tvConfig)
        {
            // 处理数据对象,转换为封装的 Camera 等对象
            CameraPanel cameraPanel = new CameraPanel {
                LayoutInfo = tvConfig.LayoutInfo
            };

            if (tvConfig.MonitorInfo != null)
            {
                List <int> indexs = tvConfig.MonitorInfo.Select(t => t.Index).Distinct().ToList();
                foreach (int index in indexs)
                {
                    List <MonitorInfo> monitors  = tvConfig.MonitorInfo.Where(t => t.Index == index).ToList();
                    CameraPanelItem    panelItem = new CameraPanelItem {
                        Index = index, RtspStrs = new List <string>(), RtmpStrs = new List <string>()
                    };
                    if (monitors.Count > 1)
                    {
                        CameraGroup cameraGroup = new CameraGroup
                        {
                            Interval = monitors[0].TimeInterval
                        };
                        foreach (var monitor in monitors)
                        {
                            DVR dvr = new DVR()
                            {
                                IP       = monitor.Ip,
                                Port     = monitor.AdminPort,
                                UserName = monitor.User,
                                Password = monitor.PassWord,
                                Id       = monitor.Id
                            };
                            Camera camera = new Camera
                            {
                                StreamType = monitor.StreamType,
                                DVR        = dvr,
                                Number     = monitor.Channel
                            };
                            cameraGroup.Items.Add(camera);
                            panelItem.RtspStrs.Add(monitor.Rtsp);
                            panelItem.RtmpStrs.Add(monitor.Rtmp);
                        }

                        panelItem.CameraGroup = cameraGroup;
                        panelItem.Flag        = monitors[0].Flag;
                        panelItem.PlayType    = PlayContentType.Group;
                    }
                    else
                    {
                        MonitorInfo monitor = monitors[0];
                        DVR         dvr     = new DVR()
                        {
                            IP       = monitor.Ip,
                            Port     = monitor.AdminPort,
                            UserName = monitor.User,
                            Password = monitor.PassWord,
                            Id       = monitor.Id
                        };

                        Camera camera = new Camera()
                        {
                            DVR        = dvr,
                            StreamType = monitor.StreamType,
                            Number     = monitor.Channel
                        };
                        panelItem.RtspStrs.Add(monitor.Rtsp);
                        panelItem.RtmpStrs.Add(monitor.Rtmp);
                        panelItem.Camera   = camera;
                        panelItem.Flag     = monitor.Flag;
                        panelItem.PlayType = PlayContentType.One;
                    }
                    cameraPanel.Cameras.Add(panelItem);
                }
            }

            gridVideo.SetValue(GridHelpers.CamearPanelProperty, cameraPanel);
        }
Example #3
0
        private ResponseData DoCommand(string netStream)
        {
            string txt = string.Empty;

            string[] commands    = null;
            string   commandName = string.Empty;
            string   paramStr    = string.Empty;

            try
            {
                string mes = "操作成功!";
                txt         = netStream;
                commands    = txt.Split('|');
                commandName = commands[0];
                paramStr    = commands[1];
                int index = -1;
                switch (commandName.ToUpper())
                {
                case "CONNECTION":
                    var param = paramStr.Split(',');
                    break;

                case "PLAYPANEL":
                    TvConfig tvConfig = JsonConvert.DeserializeObject <TvConfig>(paramStr);
                    PlayOnTV(tvConfig);
                    File.WriteAllText(basePlayPath, txt, encoding);
                    break;

                case "SETSIZE":
                    var size = paramStr.Split(',').Select(m => int.Parse(m)).ToArray();
                    WindowState = WindowState.Normal;
                    WindowStyle = WindowStyle.None;
                    ResizeMode  = ResizeMode.NoResize;
                    Topmost     = true;
                    //Top = 7;
                    //Left = 1;
                    Top    = 0;
                    Left   = 0;
                    Width  = size[0];
                    Height = size[1];
                    File.WriteAllText(sizeConfig, string.Format("width={0}\nheight={1}", Width, Height));

                    break;

                case "SINGLEPLAY":
                    index = int.Parse(paramStr);
                    SetSingle(index);
                    break;

                case "SINGLEBACK":
                    BackSingle();
                    break;

                case "STOP":
                    Stop();
                    break;

                case "EXIT":
                    this.Close();
                    break;

                case "PAUSE":
                    index = int.Parse(paramStr);
                    Pause(index);
                    break;

                case "CONTINUE":
                    index = int.Parse(paramStr);
                    Continue(index);
                    break;

                case "TEST":
                    TvConfig testConfig = JsonConvert.DeserializeObject <TvConfig>(paramStr);
                    PlayOnTV(testConfig);
                    break;

                case "PING":
                    mes = "连接成功!";
                    break;

                default:
                    mes = "不存在此操作";
                    break;
                }

                return(new ResponseData {
                    Code = 0, MessageStr = mes
                });
            }
            catch (Exception e)
            {
                Logger.Default.Error($"执行:{commandName}命令错误", e);
                return(new ResponseData {
                    Code = 1, MessageStr = "操作失败!"
                });
            }
        }
Example #4
0
        /// <summary>
        /// 播放命令操作
        /// </summary>
        /// <param name="tvConfig"></param>
        public void PlayOnTV(TvConfig tvConfig)
        {
            // 当布局变化时视频信息会变,清楚全部的 CameraPanelItem 信息
            if (tvConfig.LayoutInfo != null)
            {
                this.cameras = new Dictionary <int, CameraPanelItem>();
            }

            // 处理数据对象,转换为封装的 Camera 等对象
            CameraPanel cameraPanel = new CameraPanel {
                LayoutInfo = tvConfig.LayoutInfo
            };

            if (tvConfig.MonitorInfo != null)
            {
                List <int> indexs = tvConfig.MonitorInfo.Select(t => t.Index).Distinct().ToList();
                foreach (int index in indexs)
                {
                    List <MonitorInfo> monitors  = tvConfig.MonitorInfo.Where(t => t.Index == index).ToList();
                    CameraPanelItem    panelItem = new CameraPanelItem {
                        Index = index
                    };
                    if (monitors.Count > 1)
                    {
                        CameraGroup cameraGroup = new CameraGroup
                        {
                            Interval = monitors[0].TimeInterval
                        };
                        foreach (var monitor in monitors)
                        {
                            DVR dvr = new DVR()
                            {
                                IP       = monitor.Ip,
                                Port     = monitor.AdminPort,
                                UserName = monitor.User,
                                Password = monitor.PassWord,
                                Id       = monitor.Id
                            };
                            Camera camera = new Camera
                            {
                                StreamType = monitor.StreamType,
                                DVR        = dvr,
                                Number     = monitor.Channel
                            };
                            cameraGroup.Items.Add(camera);
                        }

                        panelItem.CameraGroup = cameraGroup;
                        panelItem.Flag        = monitors[0].Flag;
                        panelItem.PlayType    = PlayContentType.Group;
                    }
                    else
                    {
                        MonitorInfo monitor = monitors[0];
                        DVR         dvr     = new DVR()
                        {
                            IP       = monitor.Ip,
                            Port     = monitor.AdminPort,
                            UserName = monitor.User,
                            Password = monitor.PassWord,
                            Id       = monitor.Id
                        };

                        Camera camera = new Camera()
                        {
                            DVR        = dvr,
                            StreamType = monitor.StreamType,
                            Number     = monitor.Channel
                        };
                        panelItem.Camera   = camera;
                        panelItem.Flag     = monitor.Flag;
                        panelItem.PlayType = PlayContentType.One;

                        if (monitor.Ip == null && monitor.User == null)
                        {
                            panelItem.Flag = 0;
                        }
                    }
                    cameraPanel.Cameras.Add(panelItem);

                    if (this.cameras.ContainsKey(index))
                    {
                        this.cameras.Remove(index);
                    }
                    this.cameras.Add(index, panelItem);
                }

                // 登录各个设备,为后面播放,
                // 这里再返回赋值,因为每次都需要登录信息,否则失败
                foreach (var item2 in cameraPanel.Cameras)
                {
                    if (item2.Camera != null)
                    {
                        item2.Camera.DVR.Connection(false);
                    }
                    else if (item2.CameraGroup != null)
                    {
                        foreach (var item in item2.CameraGroup.Items)
                        {
                            item.DVR.Connection(false);
                        }
                    }
                }
            }

            this.gridVideo.SetValue(GridHelpers.CamearPanelProperty, cameraPanel);
        }