SetChannel Method

Summary
Sets the TV channel.
Syntax
C#
VB
C++
public void SetChannel( 
   int Channel, 
   int VideoSubChannel, 
   int AudioSubChannel 
) 
Public Sub SetChannel( _ 
   ByVal Channel As Integer, _ 
   ByVal VideoSubChannel As Integer, _ 
   ByVal AudioSubChannel As Integer _ 
)  
public: 
void SetChannel(  
   int Channel, 
   int VideoSubChannel, 
   int AudioSubChannel 
)  

Parameters

Channel
The TV channel to set.

VideoSubChannel
A predefined video Subchannel. This parameter is valid only for ATSC digital TV broadcasts.

AudioSubChannel
A predefined audio Subchannel. This parameter is valid only for ATSC digital TV broadcasts.

Remarks

Sets the TV channel. The Channel property contains the current TV channel. This method eventually converts the TV channel to a TV frequency. For a list of frequencies for channels, see the Microsoft documentation on International Analog TV Tuning. For more detailed information, refer to Microsoft documentation for IAMTVTuner.put_Channel.

Example
C#
VB
using Leadtools; 
using Leadtools.Multimedia; 
using LeadtoolsMultimediaExamples.Fixtures; 
 
public bool _result = false; 
public CaptureCtrlForm _form = new CaptureCtrlForm(); 
 
public void DigitalTVTunerExample() 
{ 
   // reference the forms capture control and tv tuner 
   CaptureCtrl capturectrl = _form.CaptureCtrl; 
 
   string outFile = Path.Combine(LEAD_VARS.MediaDir, "TVTuner_DigitalTVTunerExample.avi"); 
 
   int mainChannel = 27; 
   int subChannel = -1; 
   int newSubChannel = -1; 
   int[] subChannelList = null; 
 
   try 
   { 
      capturectrl.Preview = true; 
      // select the first digital tuner device with BDA in it's name  
      // Replace "BDA" with your video capture device name  
      if (capturectrl.VideoDevices["BDA"] != null) 
         capturectrl.VideoDevices["BDA"].Selected = true; 
 
      // set the video and audio compressors  
      capturectrl.VideoCompressors.Mpeg2.Selected = true; 
      capturectrl.AudioCompressors.AC3.Selected = true; 
 
      // get the TV Tuner device  
      TVTuner tvTuner = capturectrl.TVTuner; 
 
      // check whether the TV tuner is valid  
      if (tvTuner != null) 
      { 
         // set the input type to cable and set the channel  
         tvTuner.SetInputType(0, TunerInputType.Antenna); 
         tvTuner.SetChannel(mainChannel, -1, -1); 
 
         // get the current video sub channel 
         subChannel = tvTuner.VideoSubChannel; 
 
         // list the sub-channels for the main channle first 
         if (tvTuner.VideoSubChannelCount > 0) 
         { 
            System.Diagnostics.Debug.WriteLine(" Main Channel: " + mainChannel); 
            subChannelList = new int[tvTuner.VideoSubChannelCount]; 
            for (int i = 0; i < tvTuner.VideoSubChannelCount; i++) 
            { 
               subChannelList[i] = tvTuner.VideoSubChannelValue(i); 
               System.Diagnostics.Debug.WriteLine(" Sub Channel: " + subChannelList[i]); 
            } 
         } 
 
         // select the first sub-channel in the list 
         if (subChannelList != null && subChannelList.Length > 0) 
         { 
            tvTuner.SetChannel(mainChannel, subChannelList[0], -1); 
            mainChannel = tvTuner.Channel; 
            newSubChannel = tvTuner.VideoSubChannel; 
            System.Diagnostics.Debug.WriteLine("Selected Channel: " + mainChannel + "." + subChannel); 
         } 
 
         // if the Main and Sub channel value are postive,  
         // it means tv tuner is happay and dandy, let starts capture 
         if (mainChannel > 0 && subChannel > 0) 
         { 
            System.Diagnostics.Debug.WriteLine("Start Capturing"); 
            capturectrl.TimeLimit = 30;     // just 30 seconds of capture time  
            capturectrl.UseTimeLimit = true; 
 
            capturectrl.TargetFormat = TargetFormatType.AVI; 
            capturectrl.TargetFile = outFile; 
 
            capturectrl.StartCapture(CaptureMode.VideoAndAudio); 
         } 
      } 
 
      // we'll loop on the state and pump messages for this example.  
      // but you should not need to if running from a Windows Forms application.  
      while (capturectrl.State == CaptureState.Running) 
         Application.DoEvents(); 
 
      System.Diagnostics.Debug.WriteLine("Finish Capturing"); 
 
      // if TV tuner is valid  
      if (tvTuner != null) 
      { 
         // and set the result to what we expect  
         _result = (subChannel != newSubChannel); 
      } 
   } 
   catch (Exception ex) 
   { 
      _result = false; 
      System.Diagnostics.Debug.WriteLine(ex); 
   } 
} 
 
static class LEAD_VARS 
{ 
   public const string MediaDir = @"C:\LEADTOOLS21\Media"; 
} 
Imports Leadtools 
Imports Leadtools.Multimedia 
Imports LeadtoolsMultimediaExamples.Fixtures 
 
Public _result As Boolean = False 
Public _form As CaptureCtrlForm = New CaptureCtrlForm() 
 
Public Sub DigitalTVTunerExample() 
   ' reference the forms capture control and tv tuner 
   Dim capturectrl As CaptureCtrl = _form.CaptureCtrl 
 
   Dim outFile As String = Path.Combine(LEAD_VARS.MediaDir, "TVTuner_DigitalTVTunerExample.avi") 
 
   Dim mainChannel As Integer = 27 
   Dim subChannel As Integer = -1 
   Dim newSubChannel As Integer = -1 
   Dim subChannelList As Integer() = Nothing 
 
   Try 
      capturectrl.Preview = True 
      ' select the first digital tuner device with BDA in it's name  
      ' Replace "BDA" with your video capture device name  
      If Not capturectrl.VideoDevices("BDA") Is Nothing Then 
         capturectrl.VideoDevices("BDA").Selected = True 
      End If 
 
      ' set the video and audio compressors  
      capturectrl.VideoCompressors.Mpeg2.Selected = True 
      capturectrl.AudioCompressors.AC3.Selected = True 
 
      ' get the TV Tuner device  
      Dim tvTuner As TVTuner = capturectrl.TVTuner 
 
      ' Check if TV tuner is valid  
      If Not tvTuner Is Nothing Then 
         ' set the input type to cable and set the channel  
         tvTuner.SetInputType(0, TunerInputType.Antenna) 
         tvTuner.SetChannel(mainChannel, -1, -1) 
 
         ' get the current video sub channel 
         subChannel = tvTuner.VideoSubChannel 
 
         ' list the sub-channels for the main channle first 
         If tvTuner.VideoSubChannelCount > 0 Then 
            System.Diagnostics.Debug.WriteLine(" Main Channel: " & mainChannel) 
            subChannelList = New Integer(tvTuner.VideoSubChannelCount - 1) {} 
            Dim i As Integer = 0 
            Do While i < tvTuner.VideoSubChannelCount 
               subChannelList(i) = tvTuner.VideoSubChannelValue(i) 
               System.Diagnostics.Debug.WriteLine(" Sub Channel: " & subChannelList(i)) 
               i += 1 
            Loop 
         End If 
 
         ' select the first sub-channel in the list 
         If Not subChannelList Is Nothing AndAlso subChannelList.Length > 0 Then 
            tvTuner.SetChannel(mainChannel, subChannelList(0), -1) 
            mainChannel = tvTuner.Channel 
            newSubChannel = tvTuner.VideoSubChannel 
            System.Diagnostics.Debug.WriteLine("Selected Channel: " & mainChannel & "." & subChannel) 
         End If 
 
         ' if the Main and Sub channel value are postive, it means tv tuner is happay and dandy, let starts capture 
         If mainChannel > 0 AndAlso subChannel > 0 Then 
            System.Diagnostics.Debug.WriteLine("Start Capturing") 
            capturectrl.TimeLimit = 30 ' just 30 seconds of capture time 
            capturectrl.UseTimeLimit = True 
 
            capturectrl.TargetFormat = TargetFormatType.AVI 
            capturectrl.TargetFile = outFile 
 
            capturectrl.StartCapture(CaptureMode.VideoAndAudio) 
         End If 
      End If 
 
      ' we'll loop on the state and pump messages for this example.  
      ' but you should not need to if running from a Windows Forms application.  
      Do While capturectrl.State = CaptureState.Running 
         Application.DoEvents() 
      Loop 
 
      System.Diagnostics.Debug.WriteLine("Finish Capturing") 
 
      ' if TV tuner is valid  
      If Not tvTuner Is Nothing Then 
         ' and set the result to what we expect  
         _result = (subChannel <> newSubChannel) 
      End If 
   Catch ex As Exception 
      _result = False 
      System.Diagnostics.Debug.WriteLine(ex) 
   End Try 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const MediaDir As String = "C:\LEADTOOLS21\Media" 
End Class 
Requirements

Target Platforms

See Also

Reference

TVTuner Class

TVTuner Members

Help Version 21.0.2021.7.2
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Multimedia Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.