/// <summary> /// Creates a background worker to download audio /// </summary> /// <param name="v"></param> /// <param name="url"></param> /// <param name="dir"></param> /// <param name="progressBar"></param> public static void startDownloadAudioThread(string v, string url, string dir,ref ProgressBar progressBar,ref FormStatus childForm) { isVideo_ = false; isAudio_ = true; v_ = v; url_ = url; dir_ = dir; childForm_ = childForm; progBar_ = progressBar; audiodl = new BackgroundWorker(); audiodl.DoWork += bw_downloadAudio; audiodl.ProgressChanged += bw_updateProgressBar; audiodl.WorkerReportsProgress = true; audiodl.WorkerSupportsCancellation = true; Button cancelButton = childForm.Controls.Find("cancelButton",false)[0] as Button; cancelButton.Click += cancelDownload; if (!audiodl.IsBusy) { audiodl.RunWorkerAsync(); } }
/// <summary> /// Creates a background worker to download audio /// </summary> /// <param name="v"></param> /// <param name="url"></param> /// <param name="dir"></param> /// <param name="progressBar"></param> public static void startDownloadAudioThread(string v, string url, string dir, ref ProgressBar progressBar, ref FormStatus childForm) { isVideo_ = false; isAudio_ = true; v_ = v; url_ = url; dir_ = dir; childForm_ = childForm; progBar_ = progressBar; audiodl = new BackgroundWorker(); audiodl.DoWork += bw_downloadAudio; audiodl.ProgressChanged += bw_updateProgressBar; audiodl.WorkerReportsProgress = true; audiodl.WorkerSupportsCancellation = true; Button cancelButton = childForm.Controls.Find("cancelButton", false)[0] as Button; cancelButton.Click += cancelDownload; if (!audiodl.IsBusy) { audiodl.RunWorkerAsync(); } }
/// <summary> /// Creates a new form to show download percentage /// </summary> /// <param name="url"></param> private void RunDownload(string url) { if (isValidUrl(url)) { loadThumbNail(url.Split('=')[1]); string dir; string title = GetTitle(url.Split('=')[1]); vidTitle.Text = "Title: " + title; FormStatus childForm = new FormStatus(); ProgressBar progBar = childForm.getProgressBar(); childForm.setTitle(title); if (mp3RadioBtn.Checked) { dir = openFileLocation("mp3"); childForm.Show(); Thread audioThread = new Thread(() => Downloader.startDownloadAudioThread("mp3", url, dir, ref progBar,ref childForm)); audioThread.SetApartmentState(ApartmentState.STA); audioThread.Start(); } else if (mp4RadioBtn.Checked) { dir = openFileLocation("mp4"); childForm.Show(); Thread videoThread = new Thread(() => Downloader.startDownloadVideoThread("mp3", url, dir, ref progBar,ref childForm)); videoThread.SetApartmentState(ApartmentState.STA); videoThread.Start(); } else { dir = openFileLocation("wav"); } } }