Skip to content

Commit

Permalink
feat(audio-feedback): Play sounds when toggling event recording (#1525)
Browse files Browse the repository at this point in the history
This commit adds functionality for playing sounds on starting/stopping event recording when sound feedback is enabled.

When rapidly pressing Shift+F7, there may be some delay in sound playback as event recording takes a moment to toggle in some circumstances.

Closes #1440.
  • Loading branch information
codeofdusk authored Jan 12, 2023
1 parent a56ff3f commit fa4554f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Media;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Automation;
Expand All @@ -36,6 +39,9 @@ public partial class EventRecordControl : UserControl

public TwoStateButtonViewModel vmEventRecorder { get; private set; } = new TwoStateButtonViewModel(ButtonState.Off);

private Stream startRecordingSoundStream, stopRecordingSoundStream;
private SoundPlayer player;

/// <summary>
/// Event handler to main window for recording start
/// </summary>
Expand Down Expand Up @@ -95,8 +101,12 @@ public static ConfigurationModel AppConfiguration
public EventRecordControl()
{
InitializeComponent();

InitCommandBindings();

player = new SoundPlayer();
Assembly assembly = Assembly.GetExecutingAssembly();
startRecordingSoundStream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".Resources.Sound.start_event_recording.wav");
stopRecordingSoundStream = assembly.GetManifestResourceStream(assembly.GetName().Name + ".Resources.Sound.stop_event_recording.wav");
}

void InitCommandBindings()
Expand Down Expand Up @@ -184,6 +194,18 @@ private void onbuttonEventRecorderClicked(object sender, RoutedEventArgs e)
HollowHighlightDriver.GetDefaultInstance().Clear();
}

/// <summary>If sounds are enabled, play the passed-in stream. Used to enable sound feedback when toggling recording.</summary>
private void PlaySoundIfNeeded(Stream stream)
{
if (HelperMethods.ShouldPlaySound)
{
player.Stop();
player.Stream = stream;
player.Stream.Position = 0;
player.Play();
}
}

/// <summary>
/// Toggle event recording
/// </summary>
Expand Down Expand Up @@ -236,6 +258,8 @@ private void StartRecordingEvent()
this.tbIntro.Visibility = Visibility.Collapsed;
this.svData.Visibility = Visibility.Visible;

PlaySoundIfNeeded(startRecordingSoundStream);

this.NotifyRecordingChange(true);

Logger.PublishTelemetryEvent(TelemetryAction.Event_Start_Record);
Expand Down Expand Up @@ -310,6 +334,8 @@ await Task.Run(() =>

this.ctrlProgressRing.Deactivate();

PlaySoundIfNeeded(stopRecordingSoundStream);

this.vmEventRecorder.State = ButtonState.Off;
this.NotifyRecordingChange(false);
}
Expand Down
Binary file not shown.
Binary file not shown.
9 changes: 9 additions & 0 deletions src/AccessibilityInsights.SharedUx/SharedUx.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,13 @@
</Page>
</ItemGroup>

<ItemGroup>
<None Remove="Resources\Sound\start_event_recording.wav" />
<EmbeddedResource Include="Resources\Sound\start_event_recording.wav" />
</ItemGroup>

<ItemGroup>
<None Remove="Resources\Sound\stop_event_recording.wav" />
<EmbeddedResource Include="Resources\Sound\stop_event_recording.wav" />
</ItemGroup>
</Project>

0 comments on commit fa4554f

Please sign in to comment.