Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(audio-feedback): Add sound feedback when starting and stopping "tab stops" test #1851

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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