2 using System.Collections.Generic;
\r
3 using System.ComponentModel;
\r
5 using System.Drawing;
\r
7 using System.Windows.Forms;
\r
8 using System.Threading;
\r
9 using System.Diagnostics;
\r
10 using System.Runtime.InteropServices;
\r
12 using QTOControlLib;
\r
17 public partial class frmPreview : Form
\r
20 Handbrake.QueryGenerator hb_common_func = new Handbrake.QueryGenerator();
\r
21 Functions.Encode process = new Functions.Encode();
\r
22 private delegate void UpdateUIHandler();
\r
23 String currently_playing = "";
\r
25 private Process hbProc;
\r
26 private Thread player;
\r
28 public frmPreview(frmMain mw)
\r
30 InitializeComponent();
\r
31 this.mainWindow = mw;
\r
32 cb_preview.SelectedIndex = 0;
\r
33 cb_duration.SelectedIndex = 1;
\r
38 player = new Thread(OpenMovie);
\r
39 player.IsBackground = true;
\r
44 private void OpenMovie()
\r
48 if (this.InvokeRequired)
\r
50 this.BeginInvoke(new UpdateUIHandler(OpenMovie));
\r
53 QTControl.URL = currently_playing;
\r
54 QTControl.Width = QTControl.Movie.Width;
\r
55 QTControl.Height = QTControl.Movie.Height;
\r
56 // The initial control size is 64,64. If we do not reload the clip here
\r
57 // it'll scale the video from 64,64.
\r
58 // Unsure why as it correctly resizes the control to the movies actual size.
\r
59 QTControl.URL = currently_playing;
\r
60 QTControl.SetScale(0);
\r
63 this.Width = QTControl.Width + 5;
\r
64 this.Height = QTControl.Height + 90;
\r
66 catch (COMException ex)
\r
68 QTUtils qtu = new QTUtils();
\r
69 MessageBox.Show("Unable to open movie:\n\nError Code: " + ex.ErrorCode.ToString("X") + "\nQT Error code : " + qtu.QTErrorFromErrorCode(ex.ErrorCode).ToString());
\r
71 catch (Exception ex)
\r
73 MessageBox.Show("Unable to open movie:\n\n" + ex.ToString());
\r
77 #region Encode Sample
\r
78 private void btn_encode_Click(object sender, EventArgs e)
\r
80 btn_encode.Enabled = false;
\r
81 lbl_encode.Text = "Encoding Sample ...";
\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("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
\r
92 hbProc = process.runCli(this, (string)state);
\r
93 hbProc.WaitForExit();
\r
98 private void encodeCompleted()
\r
102 if (this.InvokeRequired)
\r
104 this.BeginInvoke(new UpdateUIHandler(encodeCompleted));
\r
107 btn_encode.Enabled = true;
\r
108 lbl_encode.Text = "Loading Clip ...";
\r
110 if (mainWindow.text_destination.Text != "")
\r
111 currently_playing = mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm");
\r
114 lbl_encode.Text = "";
\r
116 catch (Exception exc)
\r
118 MessageBox.Show("frmPreview.cs encodeCompleted " + exc.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
\r