Use PlaySound for custom bell audio to preserve mixer volume (#17733)#20031
Use PlaySound for custom bell audio to preserve mixer volume (#17733)#20031aarushisingh04 wants to merge 4 commits intomicrosoft:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
| const auto resourceUri{ winrt::Windows::Foundation::Uri{ soundPath } }; | ||
| if (resourceUri) | ||
| { | ||
| const auto uriPath{ winrt::Windows::Foundation::Uri::UnescapeComponent(resourceUri.Path()) }; |
There was a problem hiding this comment.
You always copy soundPath into another string. That's unnecessary.
A single call to PathCreateFromUrlW should do the trick for your lengthy path conversion code. The function supports input and output pointer being the same. And URI -> path is naturally always shorter than the input URI. So, this?
if (til::starts_with_insensitive_ascii(soundPath, L"file:"))
{
// Ensure that the URI has a null terminator.
std::wstring path{ soundPath };
// PathCreateFromUrlW supports writing to the input pointer,
// and the resulting path can never be longer than the URI.
const auto ptr = path.data();
auto len = gsl::narrow<DWORD>(path.size());
if (FAILED_LOG(PathCreateFromUrlW(ptr, ptr, &len, 0))) {
return;
}
path.resize(len);
}
if (!til::is_legal_path(path))
{
return;
}
PlaySoundW(filePath.c_str(), nullptr, SND_FILENAME | SND_ASYNC | SND_SENTRY | SND_NODEFAULT);(Pseudo-code.)
There was a problem hiding this comment.
switched to PathCreateFromUrlW as suggested, removed the winrt uri parsing. also fixed the scoping so filePath is declared before the if block so it's available for the legality check and playsoundw call
| { | ||
| const auto soundAlias = reinterpret_cast<LPCTSTR>(SND_ALIAS_SYSTEMHAND); | ||
| PlaySound(soundAlias, NULL, SND_ALIAS_ID | SND_ASYNC | SND_SENTRY); | ||
| auto sounds{ _profile.BellSound() }; |
There was a problem hiding this comment.
Did you use AI to make this PR? Open the file in a text editor of your choice and convert the line endings to CRLF please. AI tools tend to f line endings up. 😄
There was a problem hiding this comment.
fixed, converted to crlf throughout. sorry about that!
|
I'm not sure I understand why we need a URL parser at all. Bell sounds are resolved via IMediaResource, and by the time they get here they should be plain file paths. |
DHowett
left a comment
There was a problem hiding this comment.
My question about the URI still stands.
|
i added the URI handling because of the earlier maintainer suggestion to simplify the conversion logic if after tracing it back through the settings model though, i agree that this shouldn't be necessary here because if this sounds fine, then i'll remove the URL parsing and keep this code path focused on playing the resolved local path? |
summary of the pull request
switch bell sound playback for profile
bellSoundfiles from winrtmediaplayerto win32playsoundwto address #17733, where windows mixer volume for terminal bell audio does not persist across app restarts.references and relevant issues
detailed description of the pull request / additional comments
this change updates
terminalpanecontentto useplaysoundwwithsnd_filename | snd_async | snd_sentry | snd_nodefaultfor custom bell audio files.what changed:
mediaplayerbell playback state and lifecycle code fromterminalpanecontent._playbellsound(...)to accept a resolved sound path and callplaysoundw.file:uri-form bell paths by decoding to a filesystem path before callingplaysoundw.c:\...) without uri parsing.rationale:
known limitation:
playsoundwwithsnd_asyncis single-channel for this process path, so rapid consecutive bells may interrupt each other. this is existing acceptable behavior for this fix scope and can be revisited separately if needed.validation steps performed
manual/source validation:
bellsoundresources are resolved by settings model before playback (resolved()path).file:uri strings are converted to filesystem paths before playback.recommended manual validation on a dev machine:
bellsoundto a local.wav.pr checklist