←Select platform

AudioDevices Property

Summary

Gets the audio device collection object.

Syntax

C#
VB
C++
[EditorAttribute(System.Type, System.Type)] 
public virtual AudioDevices AudioDevices { get; } 
Public Overridable ReadOnly Property AudioDevices As Leadtools.Mediafoundation.AudioDevices 

Property Value

An AudioDevices collection object.

Remarks

The AudioDevices object is used to enumerate the available audio capture devices, and to select an audio device to capture.

Example

C#
VB
using Leadtools; 
using Leadtools.MediaFoundation; 
using LeadtoolsMediaFoundationExamples.Fixtures; 
 
public bool _result = false; 
public CaptureCtrlForm _form = new CaptureCtrlForm(); 
public CaptureCtrl _capturectrl; 
public TestCtrlSubForm _csbform; 
 
public void DevicesExample() 
{ 
   // reference the capture control 
   _capturectrl = _form.CaptureCtrl; 
 
   // input file 
   string outFile = Path.Combine(LEAD_VARS.MediaDir, "CaptureCtrl_Source.avi"); 
 
   try 
   { 
      // create the sub form for devices listbox 
      _csbform = new TestCtrlSubForm(); 
 
      _csbform.Load += new EventHandler(Form_Load); 
      _csbform.buttonRefresh.Click += new EventHandler(Refresh_Click); 
      _csbform.List.Click += new EventHandler(List_Click); 
 
      // show the devices form 
      _csbform.ShowDialog(); 
 
      // get the selected device index 
      int selectedRenderer = _capturectrl.AudioDevices.Selection; 
 
      // set the result to what we expect  
      _result = (_csbform.List.SelectedItem != null && _capturectrl.AudioDevices.Selection != -1); 
   } 
   catch (Exception) 
   { 
      _result = false; 
   } 
} 
 
void Form_Load(object sender, EventArgs e) 
{ 
   //  build the audio device list 
   EnumerateDevices(_capturectrl.AudioDevices, _csbform.List); 
} 
 
void List_Click(object sender, EventArgs e) 
{ 
   //  select the audio device 
   SelectRenderer(_capturectrl.AudioDevices, _csbform.List); 
} 
 
void Refresh_Click(object sender, EventArgs e) 
{ 
   //  refresh audio devices 
   RefreshDevices(_capturectrl.AudioDevices, _csbform.List); 
} 
 
void EnumerateDevices(AudioDevices Devices, ListBox List) 
{ 
   //  Build the devices list box 
   int Selected = -1; 
 
   // empty the list box 
   List.Items.Clear(); 
 
   // add the available audio devices to the list box 
   for (int i = 0; (i <= (Devices.Count - 1)); i++) 
   { 
      List.Items.Add(Devices[i]); 
      if (Devices[i].Selected) 
      { 
         Selected = i; 
      } 
   } 
   //  highlight the current selection 
   List.SelectedIndex = Selected; 
} 
 
void RefreshDevices(AudioDevices Devices, ListBox List) 
{ 
   string SelectedName = string.Empty; 
 
   //  save the currently selected device's name 
   if (Devices.Selection >= 0) 
      SelectedName = Devices[Devices.Selection].FriendlyName; 
 
   //  refresh the device collection 
   Devices.Refresh(); 
 
   //  if there was a previously selected renderer, reselect it 
   if (SelectedName != string.Empty) 
      Devices.Selection = Devices.IndexOf(SelectedName); 
 
   //  rebuild the listbox 
   EnumerateDevices(Devices, List); 
} 
 
void SelectRenderer(AudioDevices Devices, ListBox List) 
{ 
   //  select the highlighted device 
   Devices.Selection = Devices.IndexOf(List.Items[List.SelectedIndex] as Device); 
} 
 
static class LEAD_VARS 
{ 
   public const string MediaDir = @"C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 19\Media"; 
} 
Imports Leadtools 
Imports Leadtools.MediaFoundation 
Imports LeadtoolsMediaFoundationExamples.Fixtures 
 
Public _result As Boolean = False 
Public _form As New CaptureCtrlForm() 
Public _capturectrl As CaptureCtrl 
Public _csbform As TestCtrlSubForm 
 
Public Sub DevicesExample() 
   ' reference the capture control 
   _capturectrl = _form.CaptureCtrl 
 
   ' input file 
   Dim outFile As String = Path.Combine(LEAD_VARS.MediaDir, "CaptureCtrl_Source.avi") 
 
   Try 
      ' create the sub form for devices listbox 
      _csbform = New TestCtrlSubForm() 
 
      AddHandler _csbform.Load, AddressOf Form_Load 
      AddHandler _csbform.buttonRefresh.Click, AddressOf Refresh_Click 
      AddHandler _csbform.List.Click, AddressOf List_Click 
 
      ' show the devices form 
      _csbform.ShowDialog() 
 
      ' get the selected device index 
      Dim selectedRenderer As Integer = _capturectrl.AudioDevices.Selection 
 
      ' set the result to what we expect  
      _result = (_csbform.List.SelectedItem IsNot Nothing AndAlso _capturectrl.AudioDevices.Selection <> -1) 
   Catch generatedExceptionName As Exception 
      _result = False 
   End Try 
End Sub 
 
Private Sub Form_Load(ByVal sender As Object, ByVal e As EventArgs) 
   '  build the audio device list 
   EnumerateDevices(_capturectrl.AudioDevices, _csbform.List) 
End Sub 
 
Private Sub List_Click(ByVal sender As Object, ByVal e As EventArgs) 
   '  select the audio device 
   SelectRenderer(_capturectrl.AudioDevices, _csbform.List) 
End Sub 
 
Private Sub Refresh_Click(ByVal sender As Object, ByVal e As EventArgs) 
   '  refresh audio devices 
   RefreshDevices(_capturectrl.AudioDevices, _csbform.List) 
End Sub 
 
Private Sub EnumerateDevices(ByVal Devices As AudioDevices, ByVal List As ListBox) 
   '  Build the devices list box 
   Dim Selected As Integer = -1 
 
   ' empty the list box 
   List.Items.Clear() 
 
   ' add the available audio devices to the list box 
   Dim i As Integer = 0 
   While (i <= (Devices.Count - 1)) 
      List.Items.Add(Devices(i)) 
      If Devices(i).Selected Then 
         Selected = i 
      End If 
      i += 1 
   End While 
   '  highlight the current selection 
   List.SelectedIndex = Selected 
End Sub 
 
Private Sub RefreshDevices(ByVal Devices As AudioDevices, ByVal List As ListBox) 
   Dim SelectedName As String = String.Empty 
 
   '  save the currently selected device's name 
   If Devices.Selection >= 0 Then 
      SelectedName = Devices(Devices.Selection).FriendlyName 
   End If 
 
   '  refresh the device collection 
   Devices.Refresh() 
 
   '  if there was a previously selected renderer, reselect it 
   If SelectedName <> String.Empty Then 
      Devices.Selection = Devices.IndexOf(SelectedName) 
   End If 
 
   '  rebuild the listbox 
   EnumerateDevices(Devices, List) 
End Sub 
 
Private Sub SelectRenderer(ByVal Devices As AudioDevices, ByVal List As ListBox) 
   '  select the highlighted device 
   Devices.Selection = Devices.IndexOf(TryCast(List.Items(List.SelectedIndex), Device)) 
End Sub 
 
Public NotInheritable Class LEAD_VARS 
   Public Const MediaDir As String = "C:\Program Files (x86)\LEAD Technologies\LEADTOOLS 19\Media" 
End Class 

Requirements

Target Platforms

Help Version 19.0.2017.10.27
Products | Support | Contact Us | Copyright Notices
© 1991-2017 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.MediaFoundation Assembly