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
8 using Handbrake.Functions;
\r
14 public partial class frmPreview : Form
\r
17 QueryGenerator hb_common_func = new QueryGenerator();
\r
18 Functions.Encode process = new Functions.Encode();
\r
19 private delegate void UpdateUIHandler();
\r
20 String currently_playing = "";
\r
21 readonly frmMain mainWindow;
\r
22 private Process hbProc;
\r
23 private Thread player;
\r
24 private Boolean noQT;
\r
26 public frmPreview(frmMain mw)
\r
30 InitializeComponent();
\r
32 catch (Exception exc)
\r
34 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
35 btn_playQT.Enabled = false;
\r
38 this.mainWindow = mw;
\r
39 cb_preview.SelectedIndex = 0;
\r
40 cb_duration.SelectedIndex = 1;
\r
43 #region Encode Sample
\r
44 private void btn_playVLC_Click(object sender, EventArgs e)
\r
46 lbl_status.Visible = true;
\r
50 if (File.Exists(currently_playing))
\r
51 File.Delete(currently_playing);
\r
55 MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
58 btn_playQT.Enabled = false;
\r
59 btn_playVLC.Enabled = false;
\r
60 lbl_status.Text = "Encoding Sample for (VLC) ...";
\r
61 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
62 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
64 private void btn_playQT_Click(object sender, EventArgs e)
\r
66 lbl_status.Visible = true;
\r
70 if (File.Exists(currently_playing))
\r
71 File.Delete(currently_playing);
\r
75 MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
78 btn_playQT.Enabled = false;
\r
79 btn_playVLC.Enabled = false;
\r
80 lbl_status.Text = "Encoding Sample for (QT) ...";
\r
81 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
82 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
84 private void procMonitor(object state)
\r
86 // Make sure we are not already encoding and if we are then display an error.
\r
88 MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
91 hbProc = process.runCli(this, (string)state);
\r
92 hbProc.WaitForExit();
\r
97 private void encodeCompleted()
\r
101 if (InvokeRequired)
\r
103 BeginInvoke(new UpdateUIHandler(encodeCompleted));
\r
107 btn_playQT.Enabled = true;
\r
108 btn_playVLC.Enabled = true;
\r
110 // Decide which player to use.
\r
111 String playerSelection = lbl_status.Text.Contains("QT") ? "QT" : "VLC";
\r
113 lbl_status.Text = "Loading Clip ...";
\r
115 // Get the sample filename
\r
116 if (mainWindow.text_destination.Text != "")
\r
117 currently_playing = mainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v").Replace(".mkv", "_sample.mkv");;
\r
119 // Play back in QT or VLC
\r
120 if (playerSelection == "QT")
\r
125 lbl_status.Text = "";
\r
127 catch (Exception exc)
\r
129 MessageBox.Show(this, "frmPreview.cs encodeCompleted " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
137 /// Play the video back in the QuickTime control
\r
139 private void play()
\r
141 player = new Thread(OpenMovie) { IsBackground = true };
\r
143 lbl_status.Visible = false;
\r
147 /// Play the video back in an external VLC player
\r
149 private void playVLC()
\r
151 // Launch VLC and play video.
\r
152 if (currently_playing != "")
\r
154 if (File.Exists(currently_playing))
\r
156 if (File.Exists(Properties.Settings.Default.VLC_Path))
\r
158 String args = "\"" + currently_playing + "\"";
\r
159 ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args);
\r
160 Process.Start(vlc);
\r
161 lbl_status.Text = "VLC will now launch.";
\r
164 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
167 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
169 lbl_status.Visible = false;
\r
173 /// QT control - Open the file
\r
176 private void OpenMovie()
\r
180 if (InvokeRequired)
\r
182 BeginInvoke(new UpdateUIHandler(OpenMovie));
\r
185 QTControl.Sizing = QTSizingModeEnum.qtControlFitsMovie;
\r
186 QTControl.URL = currently_playing;
\r
187 QTControl.Sizing = QTSizingModeEnum.qtMovieFitsControl;
\r
190 this.ClientSize = QTControl.Size;
\r
193 catch (COMException ex)
\r
195 QTUtils qtu = new QTUtils();
\r
196 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
198 catch (Exception ex)
\r
200 MessageBox.Show(this, "Unable to open movie:\n\n" + ex, "QT", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r