2 using System.Collections.Generic;
\r
3 using System.ComponentModel;
\r
5 using System.Drawing;
\r
7 using System.Windows.Forms;
\r
8 using System.Threading;
\r
9 using System.Diagnostics;
\r
14 public partial class frmGenPreview : Form
\r
16 private delegate void UpdateHandler();
\r
17 Handbrake.QueryGenerator queryGen = new Handbrake.QueryGenerator();
\r
18 Functions.Encode process = new Functions.Encode();
\r
22 public frmGenPreview(frmMain mw)
\r
24 InitializeComponent();
\r
25 this.mainWindow = mw;
\r
26 cb_duration.SelectedIndex = 0;
\r
29 private void btn_play_Click(object sender, EventArgs e)
\r
31 String currently_playing;
\r
33 // Get the Destination of the sample video.
\r
34 currently_playing = "";
\r
35 if (mainWindow.text_destination.Text != "")
\r
36 currently_playing = mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm");
\r
38 // Launch VLC and play video.
\r
39 if (currently_playing != "")
\r
41 if (File.Exists(Properties.Settings.Default.VLC_Path))
\r
43 String args = "\"" + currently_playing + "\"";
\r
44 ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args);
\r
46 lbl_status.Text = "VLC will now launch.";
\r
50 MessageBox.Show("Unable to detect VLC Player. \nPlease make sure VLC is installed and the directory specified in the program options is correct.", "VLC", MessageBoxButtons.OK, MessageBoxIcon.Information);
\r
55 private void btn_encode_Click(object sender, EventArgs e)
\r
57 String query = queryGen.GeneratePreviewQuery(mainWindow, cb_duration.Text);
\r
58 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
60 private void procMonitor(object state)
\r
62 // Make sure we are not already encoding and if we are then display an error.
\r
64 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
68 hbProc = process.runCli(this, (string)state);
\r
69 hbProc.WaitForExit();
\r
74 // Update the UI now that the encode has finished.
\r
75 private void encodingMessage()
\r
79 if (this.InvokeRequired)
\r
81 this.BeginInvoke(new UpdateHandler(encodingMessage));
\r
84 lbl_status.Text = "Encoding, Please wait ...";
\r
86 catch (Exception exc)
\r
88 MessageBox.Show(exc.ToString());
\r
92 // Update the UI now that the encode has finished.
\r
93 private void updateUIElements()
\r
97 if (this.InvokeRequired)
\r
99 this.BeginInvoke(new UpdateHandler(updateUIElements));
\r
103 btn_play.Visible = true;
\r
104 toolStripSeparator1.Visible = true;
\r
105 lbl_status.Text = "Your sample is ready to play.";
\r
107 catch (Exception exc)
\r
109 MessageBox.Show(exc.ToString());
\r