/// <summary>
        /// 设置使用摄像头
        /// </summary>
        /// <param name="CameraName"></param>
        public void BindCamera(string CameraName)
        {
            if (VerStarPreview())
            {
                var cameras = XmlHelper.XmlHelper.FindAll <CameraEntity>();
                if (cameras?.Count > 0)
                {
                    var oldc = cameras.Find(m => m.Name == this._bindCameraName);
                    if (oldc != null)
                    {
                        oldc.Status = 0;
                    }
                    var newc = cameras.Find(m => m.Name == CameraName);
                    if (newc != null)
                    {
                        newc.Status = 1;
                    }
                    XmlHelper.XmlHelper.SaveList <CameraEntity>(cameras);
                }


                BindInfoEntity bindInfo = XmlHelper.XmlHelper.FindByPrimaryKey <BindInfoEntity>(this.BindInfoKey);
                if (bindInfo != null)
                {
                    bindInfo.CameraName = CameraName;
                    //TODO
                    bindInfo.Save();
                }
            }

            this._bindCameraName = CameraName;

            if (VerStarPreview())
            {
                this.Preview(this._priviewControlHandle, this._priviewControlWidth, this._priviewControlHeigh);
            }
        }
예제 #2
0
        /// <summary>
        /// 使用key方式创建摄像头操作对象
        /// </summary>
        /// <param name="Key"></param>
        /// <returns></returns>
        public static TestMulitCamera CreateCamera(string Key)
        {
            refreshDeviceInfo();

            BindInfoEntity bindInfoEntity = XmlHelper.XmlHelper.FindByPrimaryKey <BindInfoEntity>(Key);


            if (bindInfoEntity == null)
            {
                var remindCamera = XmlHelper.XmlHelper.FindAll <CameraEntity>();
                var remindAudio  = XmlHelper.XmlHelper.FindAll <AudioEntity>();

                //找到一个可用的摄像头和可用的音频设备
                var idleCamera = remindCamera.Find(m => m.Status == 0);
                var idleAudio  = remindAudio.Find(m => m.Status == 0);

                if (idleCamera == null)
                {
                    throw new Exception("无可用摄像头");
                }

                if (idleAudio == null)
                {
                    throw new Exception("无可用音频设备");
                }

                bindInfoEntity            = new BindInfoEntity();
                bindInfoEntity.Id         = Key;
                bindInfoEntity.CameraName = idleCamera.Name;
                bindInfoEntity.AudioName  = idleAudio.Name;
                bindInfoEntity.Save();

                idleCamera.Status = 1;
                idleAudio.Status  = 1;
                idleCamera.Save();
                idleAudio.Save();
            }
            else
            {
                var BindCamera = XmlHelper.XmlHelper.FindByPrimaryKey <CameraEntity>(bindInfoEntity.CameraName);
                var BindAudio  = XmlHelper.XmlHelper.FindByPrimaryKey <AudioEntity>(bindInfoEntity.AudioName);

                if (BindCamera.Status == 3 || BindAudio.Status == 3)
                {
                    //TODO 提醒是否更换摄像头或者音频设备

                    //TODO 现在默认替换摄像头
                    //找到一个可用的摄像头和可用的音频设备
                    if (BindCamera.Status == 3)
                    {
                        var remindCamera = XmlHelper.XmlHelper.FindAll <CameraEntity>();
                        var idleCamera   = remindCamera.Find(m => m.Status == 0);
                        if (idleCamera == null)
                        {
                            throw new Exception("无可用摄像头");
                        }
                        bindInfoEntity.CameraName = idleCamera.Name;
                        idleCamera.Status         = 1;
                        idleCamera.Save();
                    }

                    if (BindAudio.Status == 3)
                    {
                        var remindAudio = XmlHelper.XmlHelper.FindAll <AudioEntity>();
                        var idleAudio   = remindAudio.Find(m => m.Status == 0);
                        if (idleAudio == null)
                        {
                            throw new Exception("无可用音频设备");
                        }
                        bindInfoEntity.AudioName = idleAudio.Name;
                        idleAudio.Status         = 1;
                        idleAudio.Save();
                    }

                    bindInfoEntity.Save();
                }
            }

            TestMulitCamera testMulitCamera = new TestMulitCamera();

            testMulitCamera.BindCamera(bindInfoEntity.CameraName);
            testMulitCamera.BindAudio(bindInfoEntity.AudioName);
            testMulitCamera.BindInfoKey = Key;
            //分辨率不可调用
            //testMulitCamera.GetCameraSupportResolution();
            List <string> Resolution = GetCameraSupportResolution(bindInfoEntity.CameraName);

            //默认使用最高的分辨率
            testMulitCamera.SetResolution(Resolution.First());
            return(testMulitCamera);
        }