Example #1
0
        public async void Start(string savepath)
        {
            try
            {
                if (IsRunning)
                {
                    InfoLogger.SendInfo(_roomid, "ERROR", "已经是运行状态了。");
                    return;
                }
                //设置运行状态。
                IsRunning = true;

                //读取设置
                var config = Config.Instance;
                _downloadCommentOption = config.IsDownloadComment;
                _autoRetry             = config.IsAutoRetry;

                int.TryParse(config.Timeout ?? "2000", out _streamTimeout);

                //获取真实下载地址
                try
                {
                    _flvUrl = await PathFinder.GetTrueUrl(_roomid);
                }
                catch (WebException)
                {
                    InfoLogger.SendInfo(_roomid, "ERROR", "未取得下载地址<net>");
                    Stop(true);
                    return; //停止并退出
                }
                catch
                {
                    InfoLogger.SendInfo(_roomid, "ERROR", "未取得下载地址");
                    Stop();
                    return; //停止并退出
                }

                flvDownloader       = new FlvDownloader(_roomid, savepath, _downloadCommentOption, _commentProvider);
                flvDownloader.Info += _flvDownloader_Info;
                CheckStreaming();

                _larecordedSize = _recordedSize = 0;
                try
                {
                    flvDownloader.Start(_flvUrl);
                }
                catch (WebException e)
                {
                    InfoLogger.SendInfo(_roomid, "ERROR", "下载视频流时出错<net>:" + e.Message);
                    Stop(true);
                    return; //停止并退出
                }
                catch (Exception e)
                {
                    InfoLogger.SendInfo(_roomid, "ERROR", "下载视频流时出错:" + e.Message);
                    Stop();
                }
                _timer = new Timer((e) => {
                    if (_larecordedSize == _recordedSize)
                    {
                        InfoLogger.SendInfo(_roomid, "INFO", "接收流超时,超时时间内文件大小未有变动。");
                        Stop(true);
                    }
                    else
                    {
                        _larecordedSize = _recordedSize;
                    }
                }, null, _streamTimeout, _streamTimeout);
            }
            catch (WebException e)
            {
                InfoLogger.SendInfo(_roomid, "ERROR", "未知错误<net>:" + e.Message);
                Stop(true);
                return; //停止并退出
            }
            catch (Exception e)
            {
                InfoLogger.SendInfo(_roomid, "ERROR", "未知错误:" + e.Message);
                Stop();
            }
        }