public async void Start() { _mw.SetProcessingBtn(); if (IsRunning) { _mw.AppendLogln("ERROR", "已经是运行状态了。"); return; } //设置运行状态。 IsRunning = true; //读取设置 var originalRoomId = _mw.roomIdBox.Text; var savepath = _mw.savepathBox.Text; _downloadCommentOption = _mw.saveCommentCheckBox.IsChecked ?? true; _autoStart = _mw.waitForStreamCheckBox.IsChecked ?? true; //准备查找下载地址 var pathFinder = new PathFinder(_mw); //查找真实房间号 _roomid = await pathFinder.GetRoomid(originalRoomId); if (_roomid != null) { _mw.SetStartBtn(); } else { _mw.AppendLogln("ERROR", "未取得真实房间号"); Stop(); return; //停止并退出 } //查找真实下载地址 try { _flvUrl = await pathFinder.GetTrueUrl(_roomid); }catch { _mw.AppendLogln("ERROR", "未取得下载地址"); Stop(); return; //停止并退出 } var cmtProvider = ReceiveComment(); _flvDownloader = new FlvDownloader(_roomid, _flvUrl, savepath, _downloadCommentOption, cmtProvider); _flvDownloader.Info += _flvDownloader_Info; CheckStreaming(); try { _flvDownloader.Start(); } catch (Exception e) { _mw.AppendLogln("ERROR", "下载视频流时出错:" + e.Message); Stop(); } }
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 { InfoLogger.SendInfo(_roomid, "ERROR", "未取得下载地址"); Stop(); return; //停止并退出 } flvDownloader = new FlvDownloader(_roomid, savepath, _downloadCommentOption, _commentProvider); flvDownloader.Info += _flvDownloader_Info; CheckStreaming(); try { flvDownloader.Start(_flvUrl); } catch (Exception e) { InfoLogger.SendInfo(_roomid, "ERROR", "下载视频流时出错:" + e.Message); Stop(); } }catch (Exception e) { InfoLogger.SendInfo(_roomid, "ERROR", "未知错误:" + e.Message); Stop(); } }
public void Stop() { if (IsRunning) { IsRunning = false; _recordedSize = 0; if (flvDownloader != null) { flvDownloader.Stop(); flvDownloader = null; } InfoLogger.SendInfo(_roomid, "INFO", "停止"); OnStop?.Invoke(this); } else { InfoLogger.SendInfo(_roomid, "ERROR", "已经是停止状态了"); } }
public void Stop() { if (IsRunning) { IsRunning = false; _recordedSize = 0; if (_flvDownloader != null) { _flvDownloader.Stop(); _flvDownloader = null; } _commentProvider?.Disconnect(); _mw.AppendLogln("INFO", "停止"); } else { _mw.AppendLogln("ERROR", "已经是停止状态了"); } _mw.SetStopBtn(); }
public void Stop(bool isNetError = false) { if (IsRunning) { IsRunning = false; _recordedSize = 0; if (flvDownloader != null) { flvDownloader.Stop(); flvDownloader = null; } InfoLogger.SendInfo(_roomid, "INFO", "停止"); OnStop?.Invoke(this, isNetError); _timer?.Dispose(); } else { InfoLogger.SendInfo(_roomid, "ERROR", "已经是停止状态了"); } }
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(); } }