+ private void btn_playQT_Click(object sender, EventArgs e)\r
+ {\r
+ playWithVLC = false;\r
+ if (NoQT)\r
+ {\r
+ MessageBox.Show(this, \r
+ "It would appear QuickTime 7 is not installed or not accessible. Please (re)install QuickTime.", \r
+ "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ return;\r
+ }\r
+ if (MainWindow.text_destination.Text.Contains(".mkv"))\r
+ {\r
+ MessageBox.Show(this, \r
+ "The QuickTime Control does not support MKV files, It is recommended you use VLC option instead.", \r
+ "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);\r
+ }\r
+ else\r
+ {\r
+ ProgressBarStatus.Visible = true;\r
+ ProgressBarStatus.Value = 0;\r
+ lbl_encodeStatus.Visible = true;\r
+ try\r
+ {\r
+ QTControl.URL = string.Empty;\r
+ if (File.Exists(CurrentlyPlaying))\r
+ File.Delete(CurrentlyPlaying);\r
+ }\r
+ catch (Exception)\r
+ {\r
+ MessageBox.Show(this, \r
+ "Unable to delete previous preview file. You may need to restart the application.", \r
+ "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ }\r
+\r
+ btn_playQT.Enabled = false;\r
+ btn_playVLC.Enabled = false;\r
+ this.Text += " (Encoding)";\r
+ int duration;\r
+ int.TryParse(cb_duration.Text, out duration);\r
+ string query = QueryGenerator.GenerateCliQuery(MainWindow, 3, duration, cb_preview.Text);\r
+\r
+ ThreadPool.QueueUserWorkItem(ProcMonitor, query);\r
+ }\r
+ }\r
+\r
+ private void ProcMonitor(object state)\r
+ {\r
+ // Make sure we are not already encoding and if we are then display an error.\r
+ if (Process.HbProcess != null)\r
+ MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, \r
+ MessageBoxIcon.Warning);\r
+ else\r
+ {\r
+ Process.CreatePreviewSample((string) state);\r
+\r
+ if (Process.HbProcess != null)\r
+ {\r
+ Process.HbProcess.WaitForExit();\r
+ Process.HbProcess = null;\r
+ }\r
+ EncodeCompleted();\r
+ }\r
+ }\r
+\r
+ private void EncodeMonitorThread()\r
+ {\r
+ try\r
+ {\r
+ Parser encode = new Parser(Process.HbProcess.StandardOutput.BaseStream);\r
+ encode.OnEncodeProgress += EncodeOnEncodeProgress;\r
+ while (!encode.EndOfStream)\r
+ encode.ReadEncodeStatus();\r
+ }\r
+ catch (Exception exc)\r
+ {\r
+ MessageBox.Show(exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);\r
+ }\r
+ }\r
+\r
+ private void EncodeOnEncodeProgress(object Sender, int CurrentTask, int TaskCount, float PercentComplete, float CurrentFps, float AverageFps, TimeSpan TimeRemaining)\r
+ {\r
+ if (this.InvokeRequired)\r
+ {\r
+ this.BeginInvoke(\r
+ new EncodeProgressEventHandler(EncodeOnEncodeProgress),\r
+ new[] { Sender, CurrentTask, TaskCount, PercentComplete, CurrentFps, AverageFps, TimeRemaining });\r
+ return;\r
+ }\r
+ lbl_encodeStatus.Text = PercentComplete + "%";\r
+ ProgressBarStatus.Value = (int)Math.Round(PercentComplete);\r
+ }\r
+\r
+ private void EncodeCompleted()\r