使用C#在ProgressBar中显示下载进度

时间:2016-09-14 07:46:14

标签: c# youtube progress-bar

我正在编写代码以从YouTube下载视频 我正在使用视频图书来做到这一点。如何使用C#将下载任务与ProgressBar连接?

这是我到目前为止的代码:

cuda.jit

1 个答案:

答案 0 :(得分:0)

视频库不支持改进进度 但它在YoutubeExtractor 请参阅下面的代码段

Thread youtubeDownloader = new Thread(delegate () 
        {

            FolderBrowserDialog b = new FolderBrowserDialog();

            this.Invoke((MethodInvoker)delegate () { if (b.ShowDialog() != DialogResult.OK) return;  });
                {
                    string link = textBox1.Text;
                    IEnumerable<VideoInfo> videoInfos = DownloadUrlResolver.GetDownloadUrls(link);
                    VideoInfo video = videoInfos
                        .First(info => info.VideoType == VideoType.Mp4 && info.Resolution == 360);
                    if (video.RequiresDecryption)
                    {
                        DownloadUrlResolver.DecryptDownloadUrl(video);
                    }

                    var videoDownloader = new VideoDownloader(video, b.SelectedPath + video.Title);
                    videoDownloader.DownloadProgressChanged += (sender1, args) => this.Invoke((MethodInvoker)delegate () { progressBar1.Value = (int)args.ProgressPercentage;});
                    videoDownloader.Execute();
                }

        });
        youtubeDownloader.IsBackground = true;
        youtubeDownloader.Start();