1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace Handbrake
{
public partial class frmPreviewAX : Form
{
// !!!!!!!!!!!! WARNING !!!!!!!!!!!!
// This code may cause a Blue Screen of Death if run.
// This usually happens after the VLC active X control has been playing video for a short period
// and the user tries to close the window. Calling vlc_player.dispose() also causes this I believe.
// Patches to fix this would be very welcome!
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Handbrake.QueryGenerator hb_common_func = new Handbrake.QueryGenerator();
Functions.Encode process = new Functions.Encode();
String currently_playing = "";
frmMain mainWindow;
private Process hbProc;
Boolean playing = false;
int window_height;
int window_width;
public frmPreviewAX(frmMain mw, int w, int h)
{
InitializeComponent();
this.Width = w;
this.Height = h + statusStrip.Height + toolBar.Height;
this.mainWindow = mw;
resizeWindowUntilCorrect(w, h);
vlc_player.Height = h;
vlc_player.Width = w;
}
private void resizeWindowUntilCorrect(int w, int h)
{
// This needs fixed. It makes the window seriously slow to load.
while (vlc_player.Width != w || vlc_player.Height != h)
{
if (vlc_player.Width < w)
this.Width++;
if (vlc_player.Width > w)
this.Width--;
if (vlc_player.Height < h)
this.Height++;
if (vlc_player.Height > h)
this.Height--;
}
window_height = this.Height;
window_width = this.Width;
}
private void btn_reset_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Normal;
this.Width = window_width;
this.Height = window_height;
}
// Playback Controls
private void btn_play_Click(object sender, EventArgs e)
{
// Get the Destination of the sample video.
currently_playing = "";
if (mainWindow.text_destination.Text != "")
currently_playing = mainWindow.text_destination.Text.Replace(".m", "_sample.m").Replace(".avi", "_sample.avi").Replace(".ogm", "_sample.ogm");
if (currently_playing != "" && playing != true)
{
vlc_player.playlist.clear();
vlc_player.playlist.add(currently_playing, null, null);
vlc_player.playlist.play();
}
if (playing == false)
{
btn_play.Text = "Pause";
btn_play.Image = Handbrake.Properties.Resources.Pause;
playing = true;
}
else
{
vlc_player.playlist.togglePause();
btn_play.Text = "Play";
btn_play.Image = Handbrake.Properties.Resources.Play;
playing = false;
}
}
private void btn_stop_Click(object sender, EventArgs e)
{
if (vlc_player.playlist.isPlaying)
{
vlc_player.playlist.stop();
vlc_player.playlist.clear();
//vlc_player.Dispose(); // Causes a BlueScreen of Death!!!
btn_play.Text = "Play";
playing = false;
}
}
// Encoding a Sample
private void btn_encode_Click(object sender, EventArgs e)
{
String query;
query = hb_common_func.GeneratePreviewQuery(mainWindow,"30");
ThreadPool.QueueUserWorkItem(procMonitor, query);
}
private void procMonitor(object state)
{
// Make sure we are not already encoding and if we are then display an error.
if (hbProc != null)
MessageBox.Show("Handbrake is already encoding a video!", "Status", MessageBoxButtons.OK, MessageBoxIcon.Warning);
else
{
hbProc = process.runCli(this, (string)state);
hbProc.WaitForExit();
hbProc = null;
}
}
protected override void OnClosing(CancelEventArgs e)
{
/* try
{
while (vlc_player.playlist.isPlaying)
{
vlc_player.playlist.stop();
Thread.Sleep(100);
}
}
catch (Exception exc)
{
MessageBox.Show(exc.ToString());
}
//vlc_player.Dispose();
while (vlc_player.IsDisposed == false)
{
Thread.Sleep(100);
}
vlc_player = null;
*/
this.Dispose();
this.Hide();
}
}
}
|