我打算将 2 个或更多 USB 音频适配器(每个都有麦克风和线路)连接到我的树莓派 3。因此我需要分别枚举音频渲染和音频捕获的音频设备,并将它们显示在listbox
类似于audioinsample上。我不明白这是怎么回事。我尝试使用下面的代码,发生异常处理程序。请指教。谢谢。
captureDeviceList = new ObservableCollection<DeviceInformation>();
audioCaptureList.ItemsSource = captureDeviceList;
renderDeviceList = new ObservableCollection<DeviceInformation>();
audioRenderList.ItemsSource = renderDeviceList;
private async void enumerateAudioDevice()
{
var renderDevices = await DeviceInformation.FindAllAsync(DeviceClass.AudioRender);
if (renderDevices.Count > 0)
{
for (var i = 0; i < renderDevices.Count; i++)
{
renderDeviceList.Add(renderDevices[i]);
}
audioRenderList.SelectedItem = renderDevices[0];
}
var captureDevices = await DeviceInformation.FindAllAsync(DeviceClass.AudioCapture);
if (captureDevices.Count > 0)
{
for (var i = 0; i < captureDevices.Count; i++)
{
captureDeviceList.Add(captureDevices[i]);
}
audioCaptureList.SelectedItem = captureDevices[0];
}
}
<PivotItem Header="Info">
<Grid>
<ListBox x:Name="audioRenderList" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="288" Margin="0,25,0,0" FontSize="10"/>
<ListBox x:Name="audioCaptureList" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="288" Margin="318,25,0,0" FontSize="10"/>
<TextBlock x:Name="renderDeviceCount" HorizontalAlignment="Left" Margin="248,0,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40"/>
<TextBlock x:Name="captureDeviceCount" HorizontalAlignment="Left" Margin="566,0,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40" RenderTransformOrigin="0.425,-0.5"/>
<TextBlock HorizontalAlignment="Left" Margin="318,0,0,0" TextWrapping="Wrap" Text="Capture Devices" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Render Devices" VerticalAlignment="Top"/>
<ListBox x:Name="usbList" HorizontalAlignment="Left" Height="100" Margin="0,158,0,0" VerticalAlignment="Top" Width="288"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="USB Devices" VerticalAlignment="Top" Margin="0,133,0,0"/>
<TextBlock x:Name="usbDeviceCount" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="248,133,0,0" Width="40"/>
</Grid>
</PivotItem>
更新:我已经修改了我的 XAML 代码.. 它可以工作.. 但似乎我无法正确安排堆栈面板边距。
我在下面有我的代码。有什么建议吗?谢谢。
<PivotItem Header="Info">
<Grid>
<ListBox x:Name="audioRenderList" Margin="10,28,358,144" Width="250" Height="90">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="device:DeviceInformation">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="0,0,0,0" FontSize="18"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox x:Name="audioCaptureList" Margin="344,28,10,144" Width="250" Height="90">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="device:DeviceInformation">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="0,0,0,0" FontSize="18"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock x:Name="renderDeviceCount" HorizontalAlignment="Left" Margin="220,4,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40"/>
<TextBlock x:Name="captureDeviceCount" HorizontalAlignment="Left" Margin="560,4,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40" RenderTransformOrigin="0.425,-0.5"/>
<TextBlock HorizontalAlignment="Left" Margin="350,4,0,0" TextWrapping="Wrap" Text="Capture Devices" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Render Devices" VerticalAlignment="Top" Margin="10,4,0,0"/>
<ListBox x:Name="usbList" Margin="10,156,358,16" Width="250" Height="90">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="device:DeviceInformation">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="0,0,0,0" FontSize="18" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="USB Storage" VerticalAlignment="Top" Margin="10,131,0,0"/>
<TextBlock x:Name="usbDeviceCount" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="220,131,0,0" Width="40" RenderTransformOrigin="0.575,-0.75"/>
</Grid>
</PivotItem>
</Pivot>
2017 年 9 月 10 日更新