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
21 private Boolean noQT;
\r
23 public frmPreview(frmMain mw)
\r
27 InitializeComponent();
\r
29 catch (Exception exc)
\r
31 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
32 btn_playQT.Enabled = false;
\r
35 this.mainWindow = mw;
\r
36 cb_preview.SelectedIndex = 0;
\r
37 cb_duration.SelectedIndex = 1;
\r
40 #region Encode Sample
\r
41 private void btn_playVLC_Click(object sender, EventArgs e)
\r
43 btn_playQT.Enabled = false;
\r
44 btn_playVLC.Enabled = false;
\r
45 lbl_status.Text = "Encoding Sample for (VLC) ...";
\r
46 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
47 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
49 private void btn_playQT_Click(object sender, EventArgs e)
\r
51 btn_playQT.Enabled = false;
\r
52 btn_playVLC.Enabled = false;
\r
53 lbl_status.Text = "Encoding Sample for (QT) ...";
\r
54 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
55 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
57 private void procMonitor(object state)
\r
59 // Make sure we are not already encoding and if we are then display an error.
\r
61 MessageBox.Show(this, "Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
64 hbProc = process.runCli(this, (string)state);
\r
65 hbProc.WaitForExit();
\r
70 private void encodeCompleted()
\r
76 BeginInvoke(new UpdateUIHandler(encodeCompleted));
\r
80 btn_playQT.Enabled = true;
\r
81 btn_playVLC.Enabled = true;
\r
83 // Decide which player to use.
\r
84 String playerSelection = lbl_status.Text.Contains("QT") ? "QT" : "VLC";
\r
86 lbl_status.Text = "Loading Clip ...";
\r
88 // Get the sample filename
\r
89 if (mainWindow.text_destination.Text != "")
\r
90 currently_playing = mainWindow.text_destination.Text.Replace(".mp4", "_sample.mp4").Replace(".m4v", "_sample.m4v").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm");
\r
92 // Play back in QT or VLC
\r
93 if (playerSelection == "QT")
\r
98 lbl_status.Text = "";
\r
100 catch (Exception exc)
\r
102 MessageBox.Show(this, "frmPreview.cs encodeCompleted " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r
110 /// Play the video back in the QuickTime control
\r
112 private void play()
\r
114 player = new Thread(OpenMovie) { IsBackground = true };
\r
119 /// Play the video back in an external VLC player
\r
121 private void playVLC()
\r
123 // Launch VLC and play video.
\r
124 if (currently_playing != "")
\r
126 if (File.Exists(currently_playing))
\r
128 if (File.Exists(Properties.Settings.Default.VLC_Path))
\r
130 String args = "\"" + currently_playing + "\"";
\r
131 ProcessStartInfo vlc = new ProcessStartInfo(Properties.Settings.Default.VLC_Path, args);
\r
132 Process.Start(vlc);
\r
133 lbl_status.Text = "VLC will now launch.";
\r
136 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
139 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
144 /// QT control - Open the file
\r
147 private void OpenMovie()
\r
151 if (InvokeRequired)
\r
153 BeginInvoke(new UpdateUIHandler(OpenMovie));
\r
156 QTControl.URL = currently_playing;
\r
157 QTControl.Width = QTControl.Movie.Width;
\r
158 QTControl.Height = QTControl.Movie.Height;
\r
159 // The initial control size is 64,64. If we do not reload the clip here
\r
160 // it'll scale the video from 64,64.
\r
161 // Unsure why as it correctly resizes the control to the movies actual size.
\r
162 QTControl.URL = currently_playing;
\r
163 QTControl.SetScale(0);
\r
166 this.Width = QTControl.Width + 5;
\r
167 this.Height = QTControl.Height + 90;
\r
169 catch (COMException ex)
\r
171 QTUtils qtu = new QTUtils();
\r
172 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
174 catch (Exception ex)
\r
176 MessageBox.Show(this, "Unable to open movie:\n\n" + ex, "QT", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r