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:
Imports Leadtools.MultimediaImports Leadtools.MediaWriter
using Leadtools.Multimedia;using Leadtools.MediaWriter;
Declare the following private variable:
Private _sourceFile As StringPrivate _targetPath As StringPrivate _aborted As Boolean
private string _sourceFile;private string _targetPath;Private bool _aborted;
Add an event handler to the Form1 Load event and code it as follows:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load_sourceFile = "<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg"_targetPath = Path.Combine(Directory.GetCurrentDirectory(), "DVD")_textStatus.Text = String.Empty_buttonConvert.Enabled = True_buttonBurn.Enabled = FalseIf (Not Directory.Exists(_targetPath)) ThenDirectory.CreateDirectory(_targetPath)End IfEnd Sub
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 Sub _convertctrl_Progress(ByVal sender As System.Object, ByVal e As ProgressEventArgs) Handles _convertctrl.Progress_progress.Value = CInt((_progress.Maximum * e.percent / 100))End Sub
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 Sub _convertctrl_Complete(ByVal sender As System.Object, ByVal e As EventArgs) Handles _convertctrl.Complete_textStatus.Text = "Conversion to DVD Format Completed"_buttonBurn.Enabled = TrueEnd Sub
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 Sub _buttonConvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _buttonConvert.ClickConvertVideoToDvdFormat()End Sub
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 Sub _buttonProcessor_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _buttonProcessor.ClickBurnDvdToDisc()End Sub
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 Sub 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 formatDim tf As TargetFormat = _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 = FalseCatch ex As ExceptionMessageBox.Show(Me, ex.Message)End TryEnd SubPrivate Sub BurnDvdToDisc()_progress.Value = 0_progress.Maximum = 10000TryDim dvdBurner As MediaWriter = New MediaWriter()Dim dvdDrive As MediaWriterDrive = dvdBurner.Drives(1)Dim dvdDisc As MediaWriterDisc = dvdDrive.CreateDisc()dvdDisc.VolumeName = "DVD Volume 1"dvdDisc.InputPath = @"C:\InputFiles"dvdDrive.AutoEject = TrueAddHandler dvdDrive.OnProgress, AddressOf BurnProgress_progress.Value = 0_textStatus.Text = String.Empty_aborted = FalsedvdDrive.LoadDisc()dvdDrive.BurnDisc(dvdDisc)Do While dvdDrive.State = MediaWriterState.StateIdleApplication.DoEvents()LoopDo While dvdDrive.State = MediaWriterState.StateWritingIf _aborted ThenThrow New Exception("DVD Operation Aborted")End IfApplication.DoEvents()LoopRemoveHandler drive.OnProgress, AddressOf BurnProgress_buttonConvert.Enabled = True_buttonBurn.Enabled = TrueCatch ex As ExceptionMessageBox.Show(ex.Message)End TryEnd SubPublic Sub BurnProgress(ByVal sender As Object, ByVal evt As MediaWriterProgressEventArgs)_progress.Value = evt.Complete_textStatus.Text = evt.DescriptionIf evt.Progress = MediaWriterProgress.OperationProgressAborting Then_aborted = TrueEnd IfEnd Sub
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 formatTargetFormat 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.