我正在使用 YoutubeExtractor 的 dll .. videoDownloader_ProgressChanged 和 videoDownloader_DownloadFinished 事件在控制台应用程序中工作,但在 winform 中,它不起作用.. 我不明白为什么..
private void btnStart_Click(object sender, EventArgs e)
{
string link = textBox1.Text;
start(link);
}
static void start(string link)
{
IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);
DownloadVideo(videoInfos);
}
private static void DownloadVideo(IEnumerable<VideoInfo> videoInfos)
{
VideoInfo video = videoInfos
.First(info => info.VideoFormat == VideoFormat.Standard360);
var videoDownloader = new VideoDownloader(video, Path.Combine("C:/Downloads", video.Title + video.VideoExtension));
videoDownloader.DownloadFinished += new EventHandler(videoDownloader_DownloadFinished);
videoDownloader.ProgressChanged += new EventHandler<ProgressEventArgs>(videoDownloader_ProgressChanged);
videoDownloader.Execute();
}
static void videoDownloader_ProgressChanged(object sender, ProgressEventArgs e)
{
//some code..
}
static void videoDownloader_DownloadFinished(object sender, EventArgs e)
{
//some code..
}
我的第二个问题是,我想在静态 videoDownloader_ProgressChanged 事件中访问表单控件。e.ProgressPercentage 参数给我下载视频的百分比。我想在标签中显示它。但是由于静态事件,我无法访问标签。我尝试使用委托,但没有任何改变。