Skip to content

Commit

Permalink
feat(audio-feedback): Add sound feedback when starting and stopping "…
Browse files Browse the repository at this point in the history
…tab stops" test (#1851)

Similar to that implemented for event recording, this commit adds an audio
cue when the tab stops test is toggled and "provide feedback with sound"
is enabled.

This commit does duplicate a small quantity of code, but this is not
unprecedented for the project.

Addresses #1833.
  • Loading branch information
codeofdusk authored Sep 27, 2024
1 parent 63aa3bb commit a0d3ba9
Showing 1 changed file with 27 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using AccessibilityInsights.SharedUx.Highlighting;
using AccessibilityInsights.SharedUx.Settings;
using AccessibilityInsights.SharedUx.Telemetry;
using AccessibilityInsights.SharedUx.Utilities;
using AccessibilityInsights.SharedUx.ViewModels;
using Axe.Windows.Actions;
using Axe.Windows.Actions.Contexts;
Expand All @@ -19,7 +20,10 @@
using System;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Media;
using System.Reflection;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
Expand Down Expand Up @@ -146,12 +150,21 @@ private bool IsRecordingActive
}
}

private readonly Stream startRecordingSoundStream;
private readonly Stream stopRecordingSoundStream;
private readonly SoundPlayer player;

/// <summary>
/// Constructor
/// </summary>
public TabStopControl()
{
InitializeComponent();

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");
}

/// <summary>
Expand Down Expand Up @@ -282,6 +295,18 @@ private void TurnOffHighlighter()
this.HighlightVisibility = false;
}

/// <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 @@ -354,6 +379,7 @@ private void StartRecordingEvent()
EventHandler?.RegisterAutomationEventListener(EventType.UIA_AutomationFocusChangedEventId, this.EventMessageReceived);
lvElements.Items.Clear();
IsRecordingActive = true;
PlaySoundIfNeeded(startRecordingSoundStream);
Logger.PublishTelemetryEvent(TelemetryAction.TabStop_Record_On,
TelemetryProperty.Scope, SelectAction.GetDefaultInstance().Scope.ToString());
}
Expand Down Expand Up @@ -473,6 +499,7 @@ internal void StopRecordEvents()
{
this.EventHandler.UnregisterAutomationEventListener(EventType.UIA_AutomationFocusChangedEventId);
IsRecordingActive = false;
PlaySoundIfNeeded(stopRecordingSoundStream);
this.Toast.Visibility = Visibility.Collapsed;
}
}
Expand Down

0 comments on commit a0d3ba9

Please sign in to comment.