2 using System.Windows.Forms;
\r
3 using System.Threading;
\r
4 using System.Diagnostics;
\r
5 using System.Runtime.InteropServices;
\r
10 public partial class frmPreview : Form
\r
13 QueryGenerator hb_common_func = new QueryGenerator();
\r
14 Functions.Encode process = new Functions.Encode();
\r
15 private delegate void UpdateUIHandler();
\r
16 String currently_playing = "";
\r
18 private Process hbProc;
\r
19 private Thread player;
\r
21 public frmPreview(frmMain mw)
\r
23 InitializeComponent();
\r
24 this.mainWindow = mw;
\r
25 cb_preview.SelectedIndex = 0;
\r
26 cb_duration.SelectedIndex = 1;
\r
31 player = new Thread(OpenMovie) {IsBackground = true};
\r
36 private void OpenMovie()
\r
42 BeginInvoke(new UpdateUIHandler(OpenMovie));
\r
45 QTControl.URL = currently_playing;
\r
46 QTControl.Width = QTControl.Movie.Width;
\r
47 QTControl.Height = QTControl.Movie.Height;
\r
48 // The initial control size is 64,64. If we do not reload the clip here
\r
49 // it'll scale the video from 64,64.
\r
50 // Unsure why as it correctly resizes the control to the movies actual size.
\r
51 QTControl.URL = currently_playing;
\r
52 QTControl.SetScale(0);
\r
55 this.Width = QTControl.Width + 5;
\r
56 this.Height = QTControl.Height + 90;
\r
58 catch (COMException ex)
\r
60 QTUtils qtu = new QTUtils();
\r
61 MessageBox.Show("Unable to open movie:\n\nError Code: " + ex.ErrorCode.ToString("X") + "\nQT Error code : " + qtu.QTErrorFromErrorCode(ex.ErrorCode));
\r
63 catch (Exception ex)
\r
65 MessageBox.Show("Unable to open movie:\n\n" + ex);
\r
69 #region Encode Sample
\r
70 private void btn_encode_Click(object sender, EventArgs e)
\r
72 btn_encode.Enabled = false;
\r
73 lbl_encode.Text = "Encoding Sample ...";
\r
74 String query = hb_common_func.GeneratePreviewQuery(mainWindow, cb_duration.Text, cb_preview.Text);
\r
75 ThreadPool.QueueUserWorkItem(procMonitor, query);
\r
77 private void procMonitor(object state)
\r
79 // Make sure we are not already encoding and if we are then display an error.
\r
81 MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
84 hbProc = process.runCli(this, (string)state);
\r
85 hbProc.WaitForExit();
\r
90 private void encodeCompleted()
\r
96 BeginInvoke(new UpdateUIHandler(encodeCompleted));
\r
99 btn_encode.Enabled = true;
\r
100 lbl_encode.Text = "Loading Clip ...";
\r
102 if (mainWindow.text_destination.Text != "")
\r
103 currently_playing = mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm");
\r
106 lbl_encode.Text = "";
\r
108 catch (Exception exc)
\r
110 MessageBox.Show("frmPreview.cs encodeCompleted " + exc, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r