2 using System.Windows.Forms;
\r
3 using System.Threading;
\r
4 using System.Diagnostics;
\r
5 using System.Runtime.InteropServices;
\r
7 using AxQTOControlLib;
\r
13 public partial class frmPreview : Form
\r
16 QueryGenerator hb_common_func = new QueryGenerator();
\r
17 Functions.Encode process = new Functions.Encode();
\r
18 private delegate void UpdateUIHandler();
\r
19 String currently_playing = "";
\r
20 readonly frmMain mainWindow;
\r
21 private Process hbProc;
\r
22 private Thread player;
\r
23 private Boolean noQT;
\r
25 public frmPreview(frmMain mw)
\r
29 InitializeComponent();
\r
31 catch (Exception exc)
\r
33 MessageBox.Show(mw, "It would appear QuickTime 7 is not installed. QuickTime preview functionality will be disabled! \n\n Debug Info:\n" + exc, "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
34 btn_playQT.Enabled = false;
\r
37 this.mainWindow = mw;
\r
38 cb_preview.SelectedIndex = 0;
\r
39 cb_duration.SelectedIndex = 1;
\r
42 #region Encode Sample
\r
43 private void btn_playVLC_Click(object sender, EventArgs e)
\r
45 lbl_status.Visible = true;
\r
49 if (File.Exists(currently_playing))
\r
50 File.Delete(currently_playing);
\r
54 MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
57 btn_playQT.Enabled = false;
\r
58 btn_playVLC.Enabled = false;
\r
59 lbl_status.Text = "Encoding Sample for (VLC) ...";
\r
60 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
61 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
63 private void btn_playQT_Click(object sender, EventArgs e)
\r
65 lbl_status.Visible = true;
\r
69 if (File.Exists(currently_playing))
\r
70 File.Delete(currently_playing);
\r
74 MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
77 btn_playQT.Enabled = false;
\r
78 btn_playVLC.Enabled = false;
\r
79 lbl_status.Text = "Encoding Sample for (QT) ...";
\r
80 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
81 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
83 private void procMonitor(object state)
\r
85 // Make sure we are not already encoding and if we are then display an error.
\r
87 MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
90 hbProc = process.runCli(this, (string)state);
\r
91 hbProc.WaitForExit();
\r
96 private void encodeCompleted()
\r
100 if (InvokeRequired)
\r
102 BeginInvoke(new UpdateUIHandler(encodeCompleted));
\r
106 btn_playQT.Enabled = true;
\r
107 btn_playVLC.Enabled = true;
\r
109 // Decide which player to use.
\r
110 String playerSelection = lbl_status.Text.Contains("QT") ? "QT" : "VLC";
\r
112 lbl_status.Text = "Loading Clip ...";
\r
114 // Get the sample filename
\r
115 if (mainWindow.text_destination.Text != "")
\r
116 currently_playing = mainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v");
\r
118 // Play back in QT or VLC
\r
119 if (playerSelection == "QT")
\r
124 lbl_status.Text = "";
\r
126 catch (Exception exc)
\r
128 MessageBox.Show(this, "frmPreview.cs encodeCompleted " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
136 /// Play the video back in the QuickTime control
\r
138 private void play()
\r
140 player = new Thread(OpenMovie) { IsBackground = true };
\r
142 lbl_status.Visible = false;
\r
146 /// Play the video back in an external VLC player
\r
148 private void playVLC()
\r
150 // Launch VLC and play video.
\r
151 if (currently_playing != "")
\r
153 if (File.Exists(currently_playing))
\r
155 if (File.Exists(Properties.Settings.Default.VLC_Path))
\r
157 String args = "\"" + currently_playing + "\"";
\r
158 ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args);
\r
159 Process.Start(vlc);
\r
160 lbl_status.Text = "VLC will now launch.";
\r
163 MessageBox.Show(this, "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
166 MessageBox.Show(this, "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
168 lbl_status.Visible = false;
\r
172 /// QT control - Open the file
\r
175 private void OpenMovie()
\r
179 if (InvokeRequired)
\r
181 BeginInvoke(new UpdateUIHandler(OpenMovie));
\r
184 QTControl.Sizing = QTSizingModeEnum.qtControlFitsMovie;
\r
185 QTControl.URL = currently_playing;
\r
186 QTControl.Sizing = QTSizingModeEnum.qtMovieFitsControl;
\r
189 this.ClientSize = QTControl.Size;
\r
192 catch (COMException ex)
\r
194 QTUtils qtu = new QTUtils();
\r
195 MessageBox.Show(this, "Unable to open movie:\n\nError Code: " + ex.ErrorCode.ToString("X") + "\nQT Error code : " + qtu.QTErrorFromErrorCode(ex.ErrorCode), "QT", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
197 catch (Exception ex)
\r
199 MessageBox.Show(this, "Unable to open movie:\n\n" + ex, "QT", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r