Creating a Basic LEADTOOLS DirectShow Player Application

Perform the following steps to create and run a multimedia player application using the LEADTOOLS Multimedia PlayCtrl control.

  1. Start Visual Studio .NET.

  2. Choose File->New->Project... from the menu.

  3. In the New Project dialog box, choose either "Visual C# Projects" or "VB Projects" in the Projects Type List, and choose "Windows Forms Application" in the Templates List.

  4. Type the project name as "Multimedia Player" in the Project Name field, and then click OK. If desired, type a new location for your project or navigate to a directory using the Browse button. With the directory selected, click OK.

  5. In the "Solution Explorer" window, right-click the "References" folder, and choose "Add Reference..." from the context menu. In the "Add Reference" dialog box, click the ".NET" tab, select Leadtools.Multimedia and click OK. If this DLL does not appear under the .NET tab, click the Browse tab, navigate to the "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32" folder and select the following DLL:

    • Leadtools.Multimedia.dll

    With the DLL selected, click OK to add it to the application.

  6. Make sure Form1 is in design view. Go to the toolbox (View->Toolbox) and drag a PlayCtrl control onto the form. NOTE: If you do not have the PlayCtrl in your toolbox, from the main menu select Tools->Choose Toolbox Items. Click Browse, navigate to "<LEADTOOLS_INSTALLDIR>\Bin\Dotnet\Win32" and then select Leadtools.Multimedia.dll. Click OK. Then drag a PlayCtrl control onto the form. Set the following properties for the play control:

    Property Value
    Name _playctrl
    Anchor Top, Bottom, Left, Right
    AutoStart false
  7. Go to the toolbox (View->Toolbox) and drag a ProgressBar control onto the form (below the Play control) and set the following properties:

    Property Value
    Name _progress
    Anchor Bottom, Left, Right
    Maximum 10000
    Step 1
  8. Go to the toolbox (View->Toolbox) and drag a Button control to the bottom of the form and set the following properties:

    Property Value
    Name _buttonPlay
    Text Play
    Anchor Bottom, Right
  9. 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:

    C#
    VB
    Imports Leadtools.Multimedia 
                     
         
    using Leadtools.Multimedia; 
                     
         

  10. Declare the following private variable:

    C#
    VB
    Private _sourceFile As String 
                     
         
    private string _sourceFile; 
                     
         

  11. Add an event handler to the Form1 Load event and code it as follows:

    C#
    VB
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 
    'Note: Modify and uncomment the following line to remove the pop-up "NAG" dialog 
    'Leadtools.Multimedia.Common.MultimediaSupport.UnlockModule("YOUR LTMM KEY",Leadtools.Multimedia.Common.LockType.Application, "YOUR APPLICATION ID") 
       _sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg" 
    End Sub 
                     
         
    private void Form1_Load(object sender, System.EventArgs e) 
    { 
    //Note: Modify and uncomment the following line to remove the pop-up "NAG" dialog 
    //Leadtools.Multimedia.Common.MultimediaSupport.UnlockModule("YOUR LTMM KEY", Leadtools.Multimedia.Common.LockType.Application, "YOUR APPLICATION ID"); 
       _sourceFile = @"<LEADTOOLS_INSTALLDIR>\Media\DaDa_DVD_MPEG2.mpg"; 
    } 
                     
         

  12. Add an event handler to the _playctrl TrackingPositionChanged event and code it as follows:

    C#
    VB
    Private Sub _playctrl_TrackingPositionChanged(ByVal sender As System.Object, ByVal e As TrackingPositionChangedEventArgs) Handles _playctrl.TrackingPositionChanged 
       _progress.Value = e.position 
    End Sub 
                     
         
    private void _playctrl_TrackingPositionChanged(object sender, TrackingPositionChangedEventArgs e) 
    { 
       _progress.Value = e.position; 
    } 
                     
         

  13. Add an event handler to the _buttonPlay Click event and code it as follows:

    C#
    VB
    Private Sub _buttonPlay_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles _buttonPlay.Click 
       Try 
          _playctrl.SourceFile = _sourceFile 
          _playctrl.Run 
       Catch ex As Exception 
          MessageBox.Show(ex.Message) 
       End Try 
    End Sub    
                     
         
    private void _buttonPlay_Click(object sender, System.EventArgs e) 
    { 
       try 
       { 
          _playctrl.SourceFile = _sourceFile; 
          _playctrl.Run(); 
       } 
       catch (Exception ex) 
       { 
          MessageBox.Show(this, ex.Message); 
       } 
    } 
                     
         

  14. Build, and Run the program to test it.

Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.
Click or drag to resize