예제 #1
0
        /// <summary>
        /// The WorkerDoWork
        /// </summary>
        /// <param name="e">The e<see cref="DoWorkEventArgs"/></param>
        protected override void WorkerDoWork(DoWorkEventArgs e)
        {
            downloader.Start();
            while (downloader?.IsBusy == true)
            {
                Thread.Sleep(200);
            }

            if (_combine && _downloadSuccessful)
            {
                var audio = downloader.Files[0].Path;
                var video = downloader.Files[1].Path;

                this.ReportProgress(-1, new Dictionary <string, object>()
                {
                    { nameof(Progress), 0 }
                });
                this.ReportProgress(ProgressMax, null);

                try
                {
                    FFMpegResult <bool> result;

                    this.ReportProgress(-1, new Dictionary <string, object>()
                    {
                        { nameof(ProgressText), "Combining..." }
                    });

                    result = FFMpeg.Combine(video, audio, this.Output, delegate(int percentage)
                    {
                        // Combine progress
                        this.ReportProgress(percentage, null);
                    });

                    if (result.Value)
                    {
                        e.Result = OperationStatus.Success;
                    }
                    else
                    {
                        e.Result = OperationStatus.Failed;
                        this.ErrorsInternal.AddRange(result.Errors);
                    }

                    // Cleanup the separate audio and video files
                    FileHelper.DeleteFiles(audio, video);
                }
                catch (Exception ex)
                {
                    Logger.WriteException(ex);
                    e.Result = OperationStatus.Failed;
                }
            }
            else
            {
                e.Result = this.Status;
            }
        }