Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

Commit fa268d2

Browse files
committed
[TestAppUWP] Expose mute of local media tracks
Expose via the TestAppUWP UI the ability to mute and unmute the local audio and video tracks, in addition of the existing ability to add and remove those tracks from the peer connection.
1 parent aeb1879 commit fa268d2

2 files changed

Lines changed: 60 additions & 9 deletions

File tree

examples/TestAppUwp/MainPage.xaml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,10 +187,23 @@
187187
<Border Grid.Row="1" BorderBrush="#66000000" BorderThickness="2,2,2,2" Background="#AAFFFFFF">
188188
<MediaPlayerElement x:Name="localVideo" Height="480" Width="640" />
189189
</Border>
190-
<Grid Grid.Row="1">
191-
<Rectangle Width="125" Height="32" VerticalAlignment="Bottom" Margin="0,0,0,20" Fill="#CCFFFFFF" />
192-
<Button Grid.Row="1" Name="startLocalVideo" IsEnabled="False" Content="Start local video" VerticalAlignment="Bottom" Click="StartLocalVideoClicked" Width="125" HorizontalAlignment="Center" Margin="0,0,0,20" Height="32" />
193-
</Grid>
190+
<StackPanel Grid.Row="1" Orientation="Horizontal" Height="68" VerticalAlignment="Bottom" HorizontalAlignment="Center" Margin="0,0,0,20" Background="#CCB2D0FF" Padding="10,10,10,10" >
191+
<Button Name="startLocalMedia" IsEnabled="False" VerticalAlignment="Center" Click="StartLocalMediaClicked" Width="48" HorizontalAlignment="Center" Height="48">
192+
<SymbolIcon x:Name="startLocalMediaIcon" Symbol="Play" />
193+
</Button>
194+
<Button Name="muteLocalVideo" IsEnabled="False" VerticalAlignment="Center" Click="MuteLocalVideoClicked" Width="48" HorizontalAlignment="Center" Height="48" Margin="10,0,0,0" Padding="0,0,0,0">
195+
<Grid Width="32" Height="32" VerticalAlignment="Center">
196+
<SymbolIcon Symbol="Video" />
197+
<Path x:Name="muteLocalVideoStroke" Stroke="Black" Data="M 32,0 L 0,32" Width="32" Height="32" />
198+
</Grid>
199+
</Button>
200+
<Button Name="muteLocalAudio" IsEnabled="False" VerticalAlignment="Center" Click="MuteLocalAudioClicked" Width="48" HorizontalAlignment="Center" Height="48" Margin="10,0,0,0" Padding="0,0,0,0">
201+
<Grid Width="32" Height="32" VerticalAlignment="Center">
202+
<SymbolIcon Symbol="Microphone" />
203+
<Path x:Name="muteLocalAudioStroke" Stroke="Black" Data="M 32,0 L 0,32" Width="32" Height="32" />
204+
</Grid>
205+
</Button>
206+
</StackPanel>
194207
<Border Grid.Row="1" BorderBrush="#66000000" BorderThickness="2,2,2,2" Grid.Column="2" Background="#AAFFFFFF">
195208
<MediaPlayerElement x:Name="remoteVideo" Height="480" Width="640" />
196209
</Border>

examples/TestAppUwp/MainPage.xaml.cs

Lines changed: 43 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,8 @@ public static string GetDeviceName()
212212
public MainPage()
213213
{
214214
this.InitializeComponent();
215+
muteLocalVideoStroke.Visibility = Visibility.Collapsed;
216+
muteLocalAudioStroke.Visibility = Visibility.Collapsed;
215217

216218
RestoreLocalAndRemotePeerIDs();
217219

@@ -449,7 +451,7 @@ private async void OnLoaded(object sender, RoutedEventArgs e)
449451

450452
createOfferButton.IsEnabled = true;
451453

452-
startLocalVideo.IsEnabled = true;
454+
startLocalMedia.IsEnabled = true;
453455

454456
localVideoPlayer.CurrentStateChanged += OnMediaStateChanged;
455457
localVideoPlayer.MediaOpened += OnMediaOpened;
@@ -819,7 +821,7 @@ private void OnMediaOpened(MediaPlayer sender, object args)
819821
{
820822
RunOnMainThread(() => {
821823
localVideo.MediaPlayer.Play();
822-
//startLocalVideo.IsEnabled = true;
824+
//startLocalMedia.IsEnabled = true;
823825
});
824826
}
825827
}
@@ -1029,12 +1031,40 @@ private void UpdateRemoteAudioStats(uint channelCount, uint sampleRate)
10291031
remoteAudioSampleRate.Text = $"{sampleRate} Hz";
10301032
}
10311033

1034+
private void MuteLocalVideoClicked(object sender, RoutedEventArgs e)
1035+
{
1036+
if (_peerConnection.IsLocalVideoTrackEnabled())
1037+
{
1038+
_peerConnection.SetLocalVideoTrackEnabled(false);
1039+
muteLocalVideoStroke.Visibility = Visibility.Visible;
1040+
}
1041+
else
1042+
{
1043+
_peerConnection.SetLocalVideoTrackEnabled(true);
1044+
muteLocalVideoStroke.Visibility = Visibility.Collapsed;
1045+
}
1046+
}
1047+
1048+
private void MuteLocalAudioClicked(object sender, RoutedEventArgs e)
1049+
{
1050+
if (_peerConnection.IsLocalAudioTrackEnabled())
1051+
{
1052+
_peerConnection.SetLocalAudioTrackEnabled(false);
1053+
muteLocalAudioStroke.Visibility = Visibility.Visible;
1054+
}
1055+
else
1056+
{
1057+
_peerConnection.SetLocalAudioTrackEnabled(true);
1058+
muteLocalAudioStroke.Visibility = Visibility.Collapsed;
1059+
}
1060+
}
1061+
10321062
/// <summary>
10331063
/// Toggle local audio and video playback on/off, adding or removing tracks as needed.
10341064
/// </summary>
10351065
/// <param name="sender">The object which invoked the event.</param>
10361066
/// <param name="e">Event arguments.</param>
1037-
private async void StartLocalVideoClicked(object sender, RoutedEventArgs e)
1067+
private async void StartLocalMediaClicked(object sender, RoutedEventArgs e)
10381068
{
10391069
// Toggle between start and stop local audio/video feeds
10401070
//< TODO dssStatsTimer.IsEnabled used for toggle, but dssStatsTimer should be
@@ -1051,7 +1081,11 @@ private async void StartLocalVideoClicked(object sender, RoutedEventArgs e)
10511081
remotePresentText.Text = "Present: -";
10521082
remoteSkipText.Text = "Skip: -";
10531083
remoteLateText.Text = "Late: -";
1054-
startLocalVideo.Content = "Start local video";
1084+
muteLocalVideo.IsEnabled = false;
1085+
muteLocalAudio.IsEnabled = false;
1086+
startLocalMediaIcon.Symbol = Symbol.Play;
1087+
muteLocalAudioStroke.Visibility = Visibility.Collapsed;
1088+
muteLocalVideoStroke.Visibility = Visibility.Collapsed;
10551089
}
10561090
else
10571091
{
@@ -1134,7 +1168,11 @@ private async void StartLocalVideoClicked(object sender, RoutedEventArgs e)
11341168

11351169
dssStatsTimer.Interval = TimeSpan.FromSeconds(1.0);
11361170
dssStatsTimer.Start();
1137-
startLocalVideo.Content = "Stop local video";
1171+
muteLocalVideo.IsEnabled = true;
1172+
muteLocalAudio.IsEnabled = true;
1173+
startLocalMediaIcon.Symbol = Symbol.Stop;
1174+
muteLocalAudioStroke.Visibility = Visibility.Collapsed;
1175+
muteLocalVideoStroke.Visibility = Visibility.Collapsed;
11381176

11391177
localVideoSourceName.Text = $"({SelectedVideoCaptureDevice?.DisplayName})";
11401178
lock (_isLocalVideoPlayingLock)

0 commit comments

Comments
 (0)