Microsoft DirectX 9.0

Hosting the Video Control in a Visual Basic Form

This topic applies to Windows XP only.

This article shows how to use the Video Control to tune to a station using Visual Basic. First, create a project and add the following references:

Also add the Video Control type library as a component. Draw the video control on your form and give it a name; for example, VidControl. To tune to a channel, do the following:

  1. Obtain a tune request, as an ITuneRequest interface. This interface provides polymorphism across network types. Depending on the network, the underlying object may be an IATSCChannelTuneRequest object, an IDVBTuneRequest object, or some other type.
  2. Call the View method on the Video Control, using the tune request as the argument.
  3. Call the Run method on the Video Control.

In step 1, it is preferable to get a pre-configured tune request from a database. That way, the application does not need to handle any details related to the network type. However, you can construct a tune request from scratch if you know the particular network type that you want to support. Do the following:

  1. Create the SystemTuningSpaces collection.
  2. Create a new tune request by calling ITuningSpace.CreateTuneRequest on one of the tuning spaces in the collection.
  3. For ATSC and DVB tuning, create a locator object, and assign it to the tune request's ITuneRequest.Locator property.
  4. Set the appropriate properties on the tune request and the locator. These will depend on the network type.

For example, the following procedure tunes to ATSC channel 46 when the form loads:

Private Sub Form_Load()
    Dim objTSContainer As New SystemTuningSpaces
    Dim objTuneRequest As IATSCChannelTuneRequest
    Dim objLocator As New ATSCLocator

    Set objTuneRequest = objTSContainer("ATSC").CreateTuneRequest
    objLocator.PhysicalChannel = 46
    objTuneRequest.Locator = objLocator

    VidControl.View objTuneRequest
End Sub

The previous example specifies a tuning space in the SystemTuningSpaces collection by its unique name ("ATSC" in this example). You can also use a For...Each loop to iterate through the collection. For example, the following code populates a list box with the names of all the available tuning spaces:

For Each tunespace In objTSContainer
    TuneName = tunespace.UniqueName + " (" + tunespace.FriendlyName + ")"
    List1.AddItem TuneName

Analog cable does not require a locator object. The next example tunes to NTSC analog cable, channel 6:

Dim objTSContainer As New SystemTuningSpaces
Dim objTuneRequest As IChannelTuneRequest

Set objTuneRequest = objTSContainer("Cable").CreateTuneRequest
objTuneRequest.Channel = 6

VidControl.View objTuneRequest

As these examples show, when the application builds a tune request, it must target specific network types. If it always gets a preconfigured tune request from a database, it will function with any supported network type.

To change channels within the same network type, simply submit another tune request to the Video Control by calling MSVidCtl.View.