My Second Convert (Visual Basic)

The ltmmConvertCtrl object allows the user to recompress multimedia files or convert from one multimedia format to another. Using the following steps:

1.

Start with the project that you created in My First Convert.

2.

Choose Tools –> Menu Editor menu item.

3.

Add 1 Main menu items and 1 sub menu item to this main menu item and name them as follows. Note that menuVideoDevice is the menu item, and menuVideoDeviceAll is the sub menu item of it.

 

Name

Caption

Index

menuVideoCompressor

&Video Compressor Also known as an encoder Also known as compressor, this is a module or algorithm to compress data. Playing that data back requires a decompressor, or decoder., this is a module or algorithm to compress data. Playing that data back requires a decompressor, or decoder Also known as a decompressor, this is a module or algorithm to decompress data..

Do not fill it.

menuVideoCompressorAll

&None

0

 

4.

Add another 1 Main menu items and another 1 sub menu item to this main menu item and name them as follows. Note that menuAudioDevice is the menu item, and menuAudioDeviceAll is the sub menu item of it.

 

Name

Caption

Index

menuAudioCompressor

&Audio Compressor

Do not fill it.

menuAudioCompressorAll

&None

0

 

5.

Update the Form_Load Sub to be as follows:

Private Sub Form_Load()
   'Define the source file. 
   ltmmConvertCtrl1.SourceFile = "c:\source.avi"
   'Define the Target or output file. 
   ltmmConvertCtrl1.TargetFile = "c:\target.avi"
   ' Enumerate the Video\Audio Compressors. 
   BuildCompressorMenu
   ' Update the menu items
   UpdateMenuStatus
End Sub

6.

Handle the menuVideoCompressorAll menu item Click event, and code menuVideoCompressorAll_Click Sub as follows:

Private Sub menuVideoCompressorAll_Click(index As Integer) 
   Dim compressors As IltmmCompressors
   MousePointer = vbHourglass
   Set compressors = ltmmConvertCtrl1.VideoCompressors
   compressors.Selection = menuVideoCompressorAll(index).Tag
   Cursor = crDefault
   UpdateMenuStatus
End Sub

7.

Handle the menuAudioCompressorAll menu item Click event, and code menuAudioCompressorAll_Click Sub as follows:

Private Sub menuAudioCompressorAll_Click(index As Integer) 
   Dim compressors As IltmmCompressors
   MousePointer = vbHourglass
   Set compressors = ltmmConvertCtrl1.AudioCompressors
   compressors.Selection = menuAudioCompressorAll(index).Tag
   MousePointer = vbDefault
   UpdateMenuStatus
End Sub

8.

Add the body of BuildCompressorMenu, and UpdateMenuStatus Subs to your project.

Sub BuildCompressorMenu()
   Dim i As Integer
   Dim count As Integer
   Dim name As String
   
   count = ltmmConvertCtrl1.VideoCompressors.count
  
   menuVideoCompressorAll(0).Caption = "No Recompression"
   menuVideoCompressorAll(0).Tag = -1

   If (count > 0) Then
      For i = 0 To count - 1
         name = ltmmConvertCtrl1.VideoCompressors.Item(i).FriendlyName
         Load menuVideoCompressorAll(i + 1) 
         menuVideoCompressorAll(i + 1).Caption = name
         menuVideoCompressorAll(i + 1).Tag = i
      Next
   End If

   count = ltmmConvertCtrl1.AudioCompressors.count
   
   menuAudioCompressorAll(0).Caption = "No Recompression"
   menuAudioCompressorAll(0).Tag = -1

   If (count > 0) Then
      For i = 0 To count - 1
         name = ltmmConvertCtrl1.AudioCompressors.Item(i).FriendlyName
         Load menuAudioCompressorAll(i + 1) 
         menuAudioCompressorAll(i + 1).Caption = name
         menuAudioCompressorAll(i + 1).Tag = i
      Next
   End If
End Sub
Sub UpdateMenuStatus()
   Dim i As Integer
   Dim index As Integer
   Dim state As Boolean
   Dim compressors As IltmmCompressors

   state = (ltmmConvertCtrl1.state <> ltmmCapture_State_Running) 
   
   ' Video Compressors menu Item
   Set compressors = ltmmConvertCtrl1.VideoCompressors
   index = compressors.Selection

   For i = 0 To compressors.count
     menuVideoCompressorAll(i).Enabled = state
   Next

   For i = 0 To compressors.count
   
      If (menuVideoCompressorAll(i).Tag = index) Then
         menuVideoCompressorAll(i).Checked = True
      Else
         menuVideoCompressorAll(i).Checked = False
      End If
   Next
   
   ' Audio Compressors menu Item
   Set compressors = ltmmConvertCtrl1.AudioCompressors
   index = compressors.Selection
   
   For i = 0 To compressors.count
      menuAudioCompressorAll(i).Enabled = state
   Next

   For i = 0 To compressors.count
      If (menuAudioCompressorAll(i).Tag = index) Then
         menuAudioCompressorAll(i).Checked = True
      Else
         menuAudioCompressorAll(i).Checked = False
      End If
   Next
End Sub

9.

Handle the ltmmConvertCtrl1 Complete event, and code the ltmmConvertCtrl1_Complete Sub as follows:

Private Sub ltmmConvertCtrl1_Complete ()
   'indicate that the conversion has completed
   Caption = "Conversion completed." 
End Sub 

10.

Handle the ltmmConvertCtrl1 ErrorAbort event, and code the ltmmConvertCtrl1_ErrorAbort Sub as follows:

Private Sub ltmmConvertCtrl1_ErrorAbort(ByVal ErrorCode As Long) 
   'indicate that a conversion error has occurred
   Caption = "Error " + CStr(ErrorCode) + ". Conversion aborted." 
End Sub

11.

Handle the ltmmConvertCtrl1 Progress event, and code the ltmmConvertCtrl1_Progress Sub as follows:

Private Sub ltmmConvertCtrl1_Progress(ByVal Percent As Long) 
   'update the percentage text
   Caption = CStr(Percent) + "%"
End Sub

12.

Handle the ltmmConvertCtrl1 Started event, and code the ltmmConvertCtrl1_Started Sub as follows:

Private Sub ltmmConvertCtrl1_Started()
   Caption = "Started"
End Sub

13.

Run your program to test it.