示例#1
0
        /// <summary>
        /// 执行录制
        /// </summary>
        /// <param name="FileName">文件路径</param>
        private void DoRecord(string FileName)
        {
            bool isFinished = false;

            try
            {
                client = new WebClient();

                Stream stream = client.OpenRead(new Uri(VideoUrl[0]));

                string tmpFileName = Bas.GetFreeTmpFileName(FileName);
                tmpFileList.Add(tmpFileName);
                writer = new FileStream(tmpFileName, FileMode.Create);

                long   tmpFileLength = 0;
                byte[] mbyte         = new byte[1024];
                int    readL         = stream.Read(mbyte, 0, 1024);
                while (readL != 0 && !IsRecorderAbortRequested)
                {
                    writer.Write(mbyte, 0, readL);//写文件
                    tmpFileLength += readL;
                    //文件分片
                    if (tmpFileLength >= 1073741824)
                    {
                        //关闭连接
                        client.Dispose();
                        //关闭文件
                        writer.Close();
                        //新建分片
                        DoRecord(FileName);
                        isFinished = true;
                        return;
                    }
                    readL = stream.Read(mbyte, 0, 1024);//读流
                }
                if (IsLiving() && !IsRecorderAbortRequested)
                {
                    DoRecord(FileName);
                }
                else
                {
                    Status = StatusCode.Arranging;
                }
            }
            catch
            {
                if (IsLiving() && !IsRecorderAbortRequested)
                {
                    DoRecord(FileName);
                }
                else
                {
                    Status = StatusCode.Arranging;
                }
            }
            finally
            {
                if (!isFinished)
                {
                    //关闭连接
                    client.Dispose();
                    //关闭文件
                    writer.Close();
                    //整理文件
                    ArrangeFile();
                }
            }
        }
示例#2
0
        /// <summary>
        /// 执行录制
        /// </summary>
        private void DoRecord()
        {
            bool isFinished = false;

            try
            {
                client = new WebClient();

                Stream stream = client.OpenRead(new Uri(VideoUrl[0]));

                if (!Directory.Exists(Properties.Settings.Default.SavePath))
                {
                    Directory.CreateDirectory(Properties.Settings.Default.SavePath);
                }
                FileName = Bas.GetFreeFileName(PlatformString + "-" + Roomid + "-" + DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day + " " + DateTime.Now.Hour + "-" + DateTime.Now.Minute + "-" + DateTime.Now.Second, "flv", Properties.Settings.Default.SavePath);
                string tmpFileName = Bas.GetFreeTmpFileName(FileName);
                tmpFileList.Add(tmpFileName);
                writer = new FileStream(tmpFileName, FileMode.Create);

                long   tmpFileLength = 0;
                byte[] mbyte         = new byte[1024];
                int    readL         = stream.Read(mbyte, 0, 1024);
                while (readL != 0 && !IsRecorderAbortRequested)
                {
                    writer.Write(mbyte, 0, readL);//写文件
                    tmpFileLength += readL;
                    //文件分片
                    if (tmpFileLength >= 1073741824)
                    {
                        //关闭流
                        stream = null;
                        //关闭连接
                        client.Dispose();
                        //关闭文件
                        writer.Close();
                        //新建分片
                        DoRecord(FileName);
                        isFinished = true;
                        return;
                    }
                    readL = stream.Read(mbyte, 0, 1024);//读流
                }
                if (IsLiving() && !IsRecorderAbortRequested)
                {
                    DoRecord(FileName);
                }
                else
                {
                    Status = StatusCode.Arranging;
                }
            }
            catch
            {
                if (IsLiving() && !IsRecorderAbortRequested)
                {
                    DoRecord(FileName);
                }
                else
                {
                    Status = StatusCode.Arranging;
                }
            }
            finally
            {
                if (!isFinished)
                {
                    //关闭连接
                    client.Dispose();
                    //关闭文件
                    writer.Close();
                    //整理文件
                    ArrangeFile();
                }
            }
        }