Esempio n. 1
0
        private void btnDownloadName_Click(object sender, EventArgs e)
        {
            if (m_lDownHandle >= 0)
            {
                MessageBox.Show("Downloading, please stop firstly!");//正在下载,请先停止下载
                return;
            }

            string sVideoFileName;  //录像文件保存路径和文件名 the path and file name to save

            sVideoFileName = "Downtest_" + sPlayBackFileName + ".mp4";

            //按文件名下载 Download by file name
            m_lDownHandle = CHCNetSDK.NET_DVR_GetFileByName(m_lUserID, sPlayBackFileName, sVideoFileName);
            if (m_lDownHandle < 0)
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_GetFileByName failed, error code= " + iLastErr;
                MessageBox.Show(str);
                return;
            }

            uint iOutValue = 0;

            if (!CHCNetSDK.NET_DVR_PlayBackControl_V40(m_lDownHandle, CHCNetSDK.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue))
            {
                iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                str      = "NET_DVR_PLAYSTART failed, error code= " + iLastErr; //下载控制失败,输出错误号
                MessageBox.Show(str);
                return;
            }
            timerDownload.Interval  = 1000;
            timerDownload.Enabled   = true;
            btnStopDownload.Enabled = true;
        }
Esempio n. 2
0
        public void Download(string sPlayBackFileName)
        {
            if (DownloadHandle >= 0)
            {
                throw new Exception("正在下载,请先停止下载!");
            }

            var sVideoFileName = sPlayBackFileName + ".mp4";

            //按文件名下载 Download by file name
            DownloadHandle = CHCNetSDK.NET_DVR_GetFileByName(UserId, sPlayBackFileName, sVideoFileName);
            if (DownloadHandle < 0)
            {
                var iLastErr = NET_DVR_GetLastError();
                throw new Exception("NET_DVR_GetFileByName failed, error code= " + iLastErr);
            }

            uint iOutValue = 0;

            if (!CHCNetSDK.NET_DVR_PlayBackControl_V40(DownloadHandle, CHCNetSDK.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue))
            {
                var iLastErr = NET_DVR_GetLastError();
                throw new Exception("NET_DVR_PLAYSTART failed, error code= " + iLastErr);
            }
        }
        private async Task <Boolean> DownloadRecording(Recording recording)
        {
            if (_mLDownHandle >= 0)
            {
                Console.WriteLine("Error, already downloading!");
                return(false);
            }

            var sVideoFileName = _outputLocationPath + recording.GetFileName() + _videoExtension;

            Console.WriteLine("Downloading: " + recording.GetFileName());

            // Download from nvr/camera by file name
            _mLDownHandle = CHCNetSDK.NET_DVR_GetFileByName(_mLUserId, recording.GetFileName(),
                                                            sVideoFileName);
            if (_mLDownHandle < 0)
            {
                _iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                _errorMsg = "NET_DVR_GetFileByName failed, error code= " + _iLastErr;
                Console.WriteLine(_errorMsg);
                if (_iLastErr == 34) // Target folder does not exist, create it
                {
                    System.IO.Directory.CreateDirectory(_outputLocationPath);
                }

                return(false);
            }

            uint iOutValue = 0;

            if (!CHCNetSDK.NET_DVR_PlayBackControl_V40(_mLDownHandle, CHCNetSDK.NET_DVR_PLAYSTART,
                                                       IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue))
            {
                _iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                _errorMsg = "NET_DVR_PLAY_START failed, error code= " +
                            _iLastErr; // Download controlling failed, print error code
                Console.WriteLine(_errorMsg);
                return(false);
            }

            var downloadProgress = 0;

            while (downloadProgress < 100)
            {
                // Get downloading process
                downloadProgress = CHCNetSDK.NET_DVR_GetDownloadPos(_mLDownHandle);
                Thread.Sleep(1 * 1000);
                Console.WriteLine("Download progress: " + downloadProgress + "%");
            }

            _mLDownHandle = -1;
            return(true);
        }
Esempio n. 4
0
        public int DownloadVideoRecordByFile(int userId, string videoFileName, string fullPath)
        {
            int downloadHandle = CHCNetSDK.NET_DVR_GetFileByName(userId, videoFileName, fullPath);

            if (downloadHandle < 0)
            {
                uint   iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string str      = "NET_DVR_GetFileByName failed, error code= " + iLastErr;
                return(-1);
            }

            uint iOutValue = 0;

            if (!CHCNetSDK.NET_DVR_PlayBackControl_V40(downloadHandle, CHCNetSDK.NET_DVR_PLAYSTART, IntPtr.Zero, 0, IntPtr.Zero, ref iOutValue))
            {
                uint   iLastErr = CHCNetSDK.NET_DVR_GetLastError();
                string str      = "NET_DVR_PLAYSTART failed, error code= " + iLastErr;
                return(-1);
            }

            return(downloadHandle);
        }