2 using System.Windows.Forms;
\r
3 using System.Threading;
\r
4 using System.Diagnostics;
\r
5 using System.Runtime.InteropServices;
\r
11 public partial class frmPreview : Form
\r
14 QueryGenerator hb_common_func = new QueryGenerator();
\r
15 Functions.Encode process = new Functions.Encode();
\r
16 private delegate void UpdateUIHandler();
\r
17 String currently_playing = "";
\r
18 readonly frmMain mainWindow;
\r
19 private Process hbProc;
\r
20 private Thread player;
\r
22 public frmPreview(frmMain mw)
\r
24 InitializeComponent();
\r
25 this.mainWindow = mw;
\r
26 cb_preview.SelectedIndex = 0;
\r
27 cb_duration.SelectedIndex = 1;
\r
30 #region Encode Sample
\r
31 private void btn_playVLC_Click(object sender, EventArgs e)
\r
33 btn_playQT.Enabled = false;
\r
34 btn_playVLC.Enabled = false;
\r
35 lbl_status.Text = "Encoding Sample for (VLC) ...";
\r
36 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
37 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
39 private void btn_playQT_Click(object sender, EventArgs e)
\r
41 btn_playQT.Enabled = false;
\r
42 btn_playVLC.Enabled = false;
\r
43 lbl_status.Text = "Encoding Sample for (QT) ...";
\r
44 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
45 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
47 private void procMonitor(object state)
\r
49 // Make sure we are not already encoding and if we are then display an error.
\r
51 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
54 hbProc = process.runCli(this, (string)state);
\r
55 hbProc.WaitForExit();
\r
60 private void encodeCompleted()
\r
66 BeginInvoke(new UpdateUIHandler(encodeCompleted));
\r
69 btn_playQT.Enabled = true;
\r
70 btn_playVLC.Enabled = true;
\r
72 // Decide which player to use.
\r
73 String playerSelection = lbl_status.Text.Contains("QT") ? "QT" : "VLC";
\r
75 lbl_status.Text = "Loading Clip ...";
\r
77 // Get the sample filename
\r
78 if (mainWindow.text_destination.Text != "")
\r
79 currently_playing = mainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm");
\r
81 // Play back in QT or VLC
\r
82 if (playerSelection == "QT")
\r
87 lbl_status.Text = "";
\r
89 catch (Exception exc)
\r
91 MessageBox.Show("frmPreview.cs encodeCompleted " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
99 /// Play the video back in the QuickTime control
\r
101 private void play()
\r
103 player = new Thread(OpenMovie) { IsBackground = true };
\r
108 /// Play the video back in an external VLC player
\r
110 private void playVLC()
\r
112 // Launch VLC and play video.
\r
113 if (currently_playing != "")
\r
115 if (File.Exists(currently_playing))
\r
117 if (File.Exists(Properties.Settings.Default.VLC_Path))
\r
119 String args = "\"" + currently_playing + "\"";
\r
120 ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args);
\r
121 Process.Start(vlc);
\r
122 lbl_status.Text = "VLC will now launch.";
\r
125 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.Warning);
\r
128 MessageBox.Show("Unable to find the preview file. Either the file was deleted or the encode failed. Check the activity log for details.", "VLC", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
133 /// QT control - Open the file
\r
136 private void OpenMovie()
\r
140 if (InvokeRequired)
\r
142 BeginInvoke(new UpdateUIHandler(OpenMovie));
\r
145 QTControl.URL = currently_playing;
\r
146 QTControl.Width = QTControl.Movie.Width;
\r
147 QTControl.Height = QTControl.Movie.Height;
\r
148 // The initial control size is 64,64. If we do not reload the clip here
\r
149 // it'll scale the video from 64,64.
\r
150 // Unsure why as it correctly resizes the control to the movies actual size.
\r
151 QTControl.URL = currently_playing;
\r
152 QTControl.SetScale(0);
\r
155 this.Width = QTControl.Width + 5;
\r
156 this.Height = QTControl.Height + 90;
\r
158 catch (COMException ex)
\r
160 QTUtils qtu = new QTUtils();
\r
161 MessageBox.Show("Unable to open movie:\n\nError Code: " + ex.ErrorCode.ToString("X") + "\nQT Error code : " + qtu.QTErrorFromErrorCode(ex.ErrorCode));
\r
163 catch (Exception ex)
\r
165 MessageBox.Show("Unable to open movie:\n\n" + ex);
\r