Skip to content

Commit 18deb34

Browse files
Let the user select an output device
1 parent 00eddb7 commit 18deb34

File tree

4 files changed

+69
-7
lines changed

4 files changed

+69
-7
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<ContentDialog
2+
x:Class="VBAudioRouter.Dialogs.OutputDeviceSelectDialog"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:VBAudioRouter"
6+
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
7+
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
8+
mc:Ignorable="d"
9+
Title="Output Device"
10+
PrimaryButtonText="OK"
11+
PrimaryButtonClick="ContentDialog_PrimaryButtonClick"
12+
RequestedTheme="Dark">
13+
14+
<Grid>
15+
<ComboBox HorizontalAlignment="Stretch" x:Name="OutputDevicesComboBox" PlaceholderText="Output Device" />
16+
</Grid>
17+
</ContentDialog>
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Imports Windows.Devices.Enumeration
2+
Imports Windows.Media.Devices
3+
4+
Namespace Dialogs
5+
6+
Public NotInheritable Class OutputDeviceSelectDialog
7+
Inherits ContentDialog
8+
9+
Private Property AudioRenderDevices As DeviceInformationCollection
10+
Private Async Sub OutputDeviceSelectDialog_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
11+
If DesignMode.DesignModeEnabled Or DesignMode.DesignMode2Enabled Then Exit Sub
12+
AudioRenderDevices = Await DeviceInformation.FindAllAsync(MediaDevice.GetAudioRenderSelector())
13+
OutputDevicesComboBox.ItemsSource = AudioRenderDevices.Select(Function(device) device.Name).ToList()
14+
15+
For i As Integer = 0 To AudioRenderDevices.Count - 1
16+
If AudioRenderDevices.Item(i).IsDefault Then
17+
OutputDevicesComboBox.SelectedIndex = i
18+
Exit For
19+
End If
20+
Next
21+
End Sub
22+
23+
Public Property SelectedRenderDevice As DeviceInformation
24+
25+
Private Sub ContentDialog_PrimaryButtonClick(sender As ContentDialog, args As ContentDialogButtonClickEventArgs)
26+
If OutputDevicesComboBox.SelectedIndex < 0 Then Exit Sub
27+
SelectedRenderDevice = AudioRenderDevices(OutputDevicesComboBox.SelectedIndex)
28+
End Sub
29+
30+
31+
End Class
32+
33+
34+
End Namespace

VBAudioRouter/MainPage.xaml.vb

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
Imports VBAudioRouter.AudioGraphControl
33
Imports VBAudioRouter.Controls
44
Imports Windows.ApplicationModel.ExtendedExecution.Foreground
5+
Imports Windows.Devices.Enumeration
56
Imports Windows.Media.Audio
67
Imports Windows.System
78
Imports Windows.UI
@@ -10,7 +11,10 @@ Public NotInheritable Class MainPage
1011
Inherits Page
1112

1213
Private Async Sub MainPage_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded
13-
Await InitAudioGraphAsync(CreateGraphSettings())
14+
Dim dialog As New Dialogs.OutputDeviceSelectDialog()
15+
Await dialog.ShowAsync()
16+
17+
Await InitAudioGraphAsync(CreateGraphSettings(dialog.SelectedRenderDevice))
1418
Await EnableBackgroundAudioAsync()
1519

1620
Await DefaultOutputNode.Initialize(CurrentAudioGraph)
@@ -20,14 +24,14 @@ Public NotInheritable Class MainPage
2024
Public ReadOnly Property CurrentAudioGraph As AudioGraph = Nothing
2125

2226
Private Function CreateGraphSettings() As AudioGraphSettings
27+
Return CreateGraphSettings(Nothing)
28+
End Function
29+
Private Function CreateGraphSettings(renderDevice As DeviceInformation) As AudioGraphSettings
2330
Dim settings As New AudioGraphSettings(Windows.Media.Render.AudioRenderCategory.Media)
31+
32+
If renderDevice IsNot Nothing Then settings.PrimaryRenderDevice = renderDevice
33+
2434
settings.QuantumSizeSelectionMode = QuantumSizeSelectionMode.LowestLatency
25-
'settings.EncodingProperties = New AudioEncodingProperties()
26-
'settings.EncodingProperties.Subtype = "Float"
27-
'settings.EncodingProperties.SampleRate = 48000
28-
'settings.EncodingProperties.ChannelCount = 2
29-
'settings.EncodingProperties.BitsPerSample = 32
30-
'settings.EncodingProperties.Bitrate = 3072000
3135
Return settings
3236
End Function
3337

VBAudioRouter/VBAudioRouter.vbproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,9 @@
162162
<Compile Include="Dialogs\ErrorDialog.xaml.vb">
163163
<DependentUpon>ErrorDialog.xaml</DependentUpon>
164164
</Compile>
165+
<Compile Include="Dialogs\OutputDeviceSelectDialog.xaml.vb">
166+
<DependentUpon>OutputDeviceSelectDialog.xaml</DependentUpon>
167+
</Compile>
165168
<Compile Include="Utils\ElementWrapper.vb" />
166169
<Compile Include="Utils\MediaTransportControlsWrapper.vb" />
167170
<Compile Include="Controls\ReverbNodeControl.xaml.vb">
@@ -313,6 +316,10 @@
313316
<SubType>Designer</SubType>
314317
<Generator>MSBuild:Compile</Generator>
315318
</Page>
319+
<Page Include="Dialogs\OutputDeviceSelectDialog.xaml">
320+
<SubType>Designer</SubType>
321+
<Generator>MSBuild:Compile</Generator>
322+
</Page>
316323
<Page Include="MainPage.xaml">
317324
<Generator>MSBuild:Compile</Generator>
318325
<SubType>Designer</SubType>

0 commit comments

Comments
 (0)