Perform the following steps to create and run a multimedia video-to-DVD disc conversion application using the LEADTOOLS Multimedia ConvertCtrl control and the DVD add-on module.
Start Visual Studio.
Choose File->New->Project... from the menu.
In the New Project dialog box, choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and choose "Windows Application " in the Templates List.
Type the project name as "Multimedia Video-To-DVD Disc Converter" in the Project Name field, and then click OK. If desired, type a new location for your project or select a directory using the Browse button, and then click OK.
In the "Solution Explorer" window, right-click the "References" folder, and select "Add Reference..." from the context menu. In the "Add Reference" dialog box, select the ".NET" tab and select Leadtools.Multimedia and Leadtools.MediaWriter and click OK.
Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and drag a ConvertCtrl control on the form. NOTE: If you do not have ConvertCtrl in your toolbox, select Tools->Choose Toolbox Items from the menu. Click Browse and then select Leadtools.Multimedia.dll from "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet4\Win32" and then click Open and then click OK. After adding it to the form, set the following properties on the convert control:
Property | Value |
---|---|
Name | _convertctrl |
Anchor | Top, Bottom, Left, Right |
BackColor | Black |
Go to the toolbox (View->Toolbox) and drag a ProgressBar control on the form (below the convert control) and set the following properties:
Property | Value |
---|---|
Name | _progress |
Anchor | Bottom, Left, Right |
Step | 1 |
Go to the toolbox (View->Toolbox) and drag a Text control on the form (below the progress control) and set the following properties:
Property | Value |
---|---|
Name | _textStatus |
Anchor | Bottom, Left |
BorderStyle | None |
BackColor | Control |
ForeColor | Highlight |
Go to the toolbox (View->Toolbox) and drag two Button controls to the bottom of the form and set the following properties:
Property | Value |
---|---|
Name | _buttonConvert |
Text | Convert |
Anchor | Bottom, Right |
Name | _buttonBurn |
Text | Burn |
Anchor | Bottom, Right |
Switch Form1 to code view (right-click Form1 in the Solution Explorer then choose View Code) and add the following lines to the beginning of the file:
using Leadtools.Multimedia;
using Leadtools.MediaWriter;
Declare the following private variable:
private string _sourceFile;
private string _targetPath;
Private bool _aborted;
Add an event handler to the Form1 Load event and code it as follows:
private void Form1_Load(object sender, System.EventArgs e)
{
_sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg";
_targetPath = Path.Combine(Directory.GetCurrentDirectory(), "DVD");
_textStatus.Text = string.Empty;
_buttonConvert.Enabled = true;
_buttonBurn.Enabled = false;
if (!Directory.Exists(_targetPath))
Directory.CreateDirectory(_targetPath);
}
Add an event handler to the _convertctrl Progress event and code it as follows:
private void _convertctrl_Progress(object sender, ProgressEventArgs e)
{
_progress.Value = (int)(_progress.Maximum * e.percent / 100);
}
Add an event handler to the _convertctrl Complete event and code it as follows:
private void _convertctrl_Complete(object sender, EventArgs e)
{
_textStatus.Text = "Conversion to DVD Format Completed";
_buttonBurn.Enabled = true;
}
Add an event handler to the _buttonConvert Click event and code it as follows:
private void _buttonConvert_Click(object sender, System.EventArgs e)
{
ConvertVideoToDvdFormat();
}
Add an event handler to the _buttonBurn Click event and code it as follows:
private void _buttonProcessor_Click(object sender, System.EventArgs e)
{
BurnDvdToDisc()
}
Add the following helper methods for use by the _buttonConvert and _buttonBurn event handlers:
private void ConvertVideoToDvdFormat()
{
try
{
_convertctrl.Preview = true;
_convertctrl.SourceFile = _sourceFile;
// select video and audio compressors
_convertctrl.VideoCompressors.Mpeg2.Selected = true;
_convertctrl.AudioCompressors.AC3.Selected = true;
// select the DVD target format
TargetFormat tf = _convertctrl.TargetFormats[TargetFormatType.DVD];
tf.Selected = true;
// set the allowed capture streams
_convertctrl.AllowedStreams = tf.Streams;
_convertctrl.TargetFile = _targetPath;
_convertctrl.StartConvert();
_textStatus.Text = "Converting Video to DVD Format";
_buttonBurn.Enabled = false;
_buttonConvert.Enabled = false;
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message);
}
}
private void BurnDvdToDisc()
{
_progress.Value = 0;
_progress.Maximum = 10000;
try
{
MediaWriter dvdBurner = new MediaWriter();
MediaWriterDrive dvdDrive = dvdBurner.Drives[1];
MediaWriterDisc dvdDisc = dvdDrive.CreateDisc();
dvdDisc.VolumeName = "DVD Volume 1";
dvdDisc.InputPath = @"C:\InputFiles";
dvdDrive.AutoEject = true;
dvdDrive.OnProgress += BurnProgress;
_progress.Value = 0;
_textStatus.Text = String.Empty;
_aborted = false;
dvdDrive.LoadDisc();
dvdDrive.BurnDisc(dvdDisc);
while (dvdDrive.State = MediaWriterState.StateIdle)
{
Application.DoEvents();
}
While (dvdDrive.State = MediaWriterState.StateWriting)
{
if (_aborted)
{
throw new Exception("DVD Operation Aborted");
}
Application.DoEvents();
}
drive.OnProgress -= BurnProgress;
_buttonConvert.Enabled = true;
_buttonBurn.Enabled = True
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
public void BurnProgress(Object sender, EventArgs evt)
{
_progress.Value = evt.Complete;
_textStatus.Text = evt.Description;
if (evt.Progress == MediaWriterProgress.OperationProgressAborting)
{
_aborted = true;
}
}
Build, and Run the program to test it.