Selected Property

Summary
Gets or sets a value that indicates if this audio format object is currently selected.
Syntax
C#
VB
C++
public bool Selected {get; set;} 
Public Property Selected As Boolean 
public: 
property bool Selected { 
   bool get(); 
   void set (    bool ); 
} 

Property Value

true if the audio format is selected; otherwise, it is false

Remarks

If the format is currently selected, changing its selection state will have no effect. One format must be selected at any time.

Example
C#
VB
using Leadtools; 
using Leadtools.MediaFoundation; 
using LeadtoolsMediaFoundationExamples.Fixtures; 
 
public CaptureCtrlForm _form = new CaptureCtrlForm(); 
public bool _result = false; 
 
public void AudioFormatExample() 
{ 
   try 
   { 
      int count, freq = 0, bits = 0, channels = 0; 
      int found, selected = -1; 
 
      // reference the capture control 
      CaptureCtrl capturectrl = _form.CaptureCtrl; 
 
      // set an audio device, use the name of your device here 
      if (capturectrl.AudioDevices["USB"] == null) 
         throw new Exception("No USB audio device available"); 
 
      capturectrl.AudioDevices["USB"].Selected = true; 
 
      // get count of available audio formats 
      count = capturectrl.AudioCaptureFormats.Count; 
 
      // reset the current selection to -1 
      capturectrl.AudioCaptureFormats.Selection = -1; 
 
      // reference the audioformats property 
      AudioFormats audioformats = capturectrl.AudioCaptureFormats; 
 
      // enumerate formats and select one 
      foreach (AudioFormat af in audioformats) 
      { 
         freq = af.SampleFrequency; 
         bits = af.BitsPerSample; 
         channels = af.Channels; 
 
         // select the format if it matches some criteria 
         if (freq == 8000 && bits == 16 && channels == 2) 
         { 
            af.Selected = true; 
            break; 
         } 
      } 
 
      // get the currently selected format 
      selected = audioformats.Selection; 
 
      // find a format based on frequency, bits/channel and number of channels 
      found = audioformats.IndexOf(8000, 8, 2); 
 
      // our found format is not selected, so select it 
      if (found != selected) 
         audioformats.Selection = found; 
 
      // get the new selected format 
      selected = audioformats.Selection; 
 
      // set our result based on what we expect 
      _result = (count > 0 && selected == found); 
   } 
   catch (Exception) 
   { 
      _result = false; 
   } 
} 
Imports Leadtools 
Imports Leadtools.MediaFoundation 
Imports LeadtoolsMediaFoundationExamples.Fixtures 
 
Public _form As CaptureCtrlForm = New CaptureCtrlForm() 
Public _result As Boolean = False 
 
Public Sub AudioFormatExample() 
   Try 
      Dim count As Integer, freq As Integer = 0, bits As Integer = 0, channels As Integer = 0 
      Dim found As Integer, selected As Integer = -1 
 
      ' reference the capture control 
      Dim capturectrl As CaptureCtrl = _form.CaptureCtrl 
 
      ' set an audio device, use the name of your device here 
      If capturectrl.AudioDevices("USB") Is Nothing Then 
         Throw New Exception("No USB audio device available") 
      End If 
 
      capturectrl.AudioDevices("USB").Selected = True 
 
      ' get count of available audio formats 
      count = capturectrl.AudioCaptureFormats.Count 
 
      ' reset the current selection to -1 
      capturectrl.AudioCaptureFormats.Selection = -1 
 
      ' reference the audioformats property 
      Dim audioformats As AudioFormats = capturectrl.AudioCaptureFormats 
 
      ' enumerate formats and select one 
      For Each af As AudioFormat In audioformats 
         freq = af.SampleFrequency 
         bits = af.BitsPerSample 
         channels = af.Channels 
 
         ' select the format if it matches some criteria 
         If freq = 8000 AndAlso bits = 16 AndAlso channels = 2 Then 
            af.Selected = True 
            Exit For 
         End If 
      Next af 
 
      ' get the currently selected format 
      selected = audioformats.Selection 
 
      ' find a format based on frequency, bits/channel and number of channels 
      found = audioformats.IndexOf(8000, 8, 2) 
 
      ' our found format is not selected, so select it 
      If found <> selected Then 
         audioformats.Selection = found 
      End If 
 
      ' get the new selected format 
      selected = audioformats.Selection 
 
      ' set our result based on what we expect 
      _result = (count > 0 AndAlso selected = found) 
   Catch e1 As Exception 
      _result = False 
   End Try 
End Sub 
Requirements

Target Platforms

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

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