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.EncodeQueue;
\r
9 using Handbrake.Functions;
\r
10 using QTOControlLib;
\r
15 public partial class frmPreview : Form
\r
18 QueryGenerator hb_common_func = new QueryGenerator();
\r
19 Encode process = new Encode();
\r
20 private delegate void UpdateUIHandler();
\r
21 String currently_playing = "";
\r
22 readonly frmMain mainWindow;
\r
23 private Process hbProc;
\r
24 private Thread player;
\r
25 private Boolean noQT;
\r
27 public frmPreview(frmMain mw)
\r
31 InitializeComponent();
\r
33 catch (Exception exc)
\r
35 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
36 btn_playQT.Enabled = false;
\r
39 this.mainWindow = mw;
\r
40 cb_preview.SelectedIndex = 0;
\r
41 cb_duration.SelectedIndex = 1;
\r
44 #region Encode Sample
\r
45 private void btn_playVLC_Click(object sender, EventArgs e)
\r
47 lbl_status.Visible = true;
\r
51 if (File.Exists(currently_playing))
\r
52 File.Delete(currently_playing);
\r
56 MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
59 btn_playQT.Enabled = false;
\r
60 btn_playVLC.Enabled = false;
\r
61 lbl_status.Text = "Encoding Sample for (VLC) ...";
\r
62 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
63 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
65 private void btn_playQT_Click(object sender, EventArgs e)
\r
67 lbl_status.Visible = true;
\r
71 if (File.Exists(currently_playing))
\r
72 File.Delete(currently_playing);
\r
76 MessageBox.Show(this, "Unable to delete previous preview file. You may need to restart the application.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
79 btn_playQT.Enabled = false;
\r
80 btn_playVLC.Enabled = false;
\r
81 lbl_status.Text = "Encoding Sample for (QT) ...";
\r
82 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
83 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
85 private void procMonitor(object state)
\r
87 // Make sure we are not already encoding and if we are then display an error.
\r
89 MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
92 hbProc = process.runCli((string)state).hbProcProcess;
\r
93 hbProc.WaitForExit();
\r
98 private void encodeCompleted()
\r
102 if (InvokeRequired)
\r
104 BeginInvoke(new UpdateUIHandler(encodeCompleted));
\r
108 btn_playQT.Enabled = true;
\r
109 btn_playVLC.Enabled = true;
\r
111 // Decide which player to use.
\r
112 String playerSelection = lbl_status.Text.Contains("QT") ? "QT" : "VLC";
\r
114 lbl_status.Text = "Loading Clip ...";
\r
116 // Get the sample filename
\r
117 if (mainWindow.text_destination.Text != "")
\r
118 currently_playing = mainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v").Replace(".mkv", "_sample.mkv");;
\r
120 // Play back in QT or VLC
\r
121 if (playerSelection == "QT")
\r
126 lbl_status.Text = "";
\r
128 catch (Exception exc)
\r
130 MessageBox.Show(this, "frmPreview.cs encodeCompleted " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
138 /// Play the video back in the QuickTime control
\r
140 private void play()
\r
142 player = new Thread(OpenMovie) { IsBackground = true };
\r
144 lbl_status.Visible = false;
\r
148 /// Play the video back in an external VLC player
\r
150 private void playVLC()
\r
152 // Launch VLC and play video.
\r
153 if (currently_playing != "")
\r
155 if (File.Exists(currently_playing))
\r
157 if (File.Exists(Properties.Settings.Default.VLC_Path))
\r
159 String args = "\"" + currently_playing + "\"";
\r
160 ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args);
\r
161 Process.Start(vlc);
\r
162 lbl_status.Text = "VLC will now launch.";
\r
165 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
168 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
170 lbl_status.Visible = false;
\r
174 /// QT control - Open the file
\r
177 private void OpenMovie()
\r
181 if (InvokeRequired)
\r
183 BeginInvoke(new UpdateUIHandler(OpenMovie));
\r
186 QTControl.Sizing = QTSizingModeEnum.qtControlFitsMovie;
\r
187 QTControl.URL = currently_playing;
\r
188 QTControl.Sizing = QTSizingModeEnum.qtMovieFitsControl;
\r
191 this.ClientSize = QTControl.Size;
\r
194 catch (COMException ex)
\r
196 QTUtils qtu = new QTUtils();
\r
197 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
199 catch (Exception ex)
\r
201 MessageBox.Show(this, "Unable to open movie:\n\n" + ex, "QT", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r