gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 05:24:31 24 4
gpt4 key购买 nike

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

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

private async void buttondownload_Click(object sender, EventArgs e)
{
try
{
using (FolderBrowserDialog fbd = new FolderBrowserDialog() { Description = "select your path ." })
{
if (fbd.ShowDialog() == DialogResult.OK)
{
var youtube = YouTube.Default;
labelstatus.Text = "Downloading....";
var video = await youtube.GetVideoAsync(textBoxurl.Text);
//setting progress bar...............................??????

File.WriteAllBytes(fbd.SelectedPath + video.FullName, await video.GetBytesAsync());
labelstatus.Text = "Completed!";
}
}
}

最佳答案

视频库不支持进度更改
但它在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();

关于c# - 使用C#在ProgressBar中显示下载进度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39485085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com