Custom Audio does not work on UWP as indicted in the docs

Josh N 26 Reputation points Microsoft Employee
2021-03-22T23:27:41.547+00:00

I tried implementing custom audio however for the locally deployed app it does not work. My windows version is 20H2. The toast is displayed however it is silent no audio is played.
The code is as below

            // Construct the content
            var contentBuilder = new ToastContentBuilder()
                .AddToastActivationInfo("app-defined-string", ToastActivationType.Foreground)
                .AddText(titleText)
                .AddText("Some text here")
                // Profile (app logo override) image
                .AddAppLogoOverride(logoOverrideUri, ToastGenericAppLogoCrop.Circle);

            // If we're running on Desktop before Version 1511, do NOT include custom audio
            // since it was not supported until Version 1511, and would result in a silent toast.

            var supportsCustomAudio = !(AnalyticsInfo.VersionInfo.DeviceFamily.Equals("Windows.Desktop")
                                         && !ApiInformation.IsApiContractPresent(
                                             "Windows.Foundation.UniversalApiContract", 2));

            if (supportsCustomAudio)
            {
                contentBuilder.AddAudio(new Uri("ms-appx:///Assets/Audio/ToastNotificationSound.wav"));
            }

            // Send the toast
            contentBuilder.Show();
Universal Windows Platform (UWP)
{count} vote

Accepted answer
  1. Nico Zhu (Shanghai Wicresoft Co,.Ltd.) 12,851 Reputation points
    2021-03-26T06:51:11.157+00:00

    Hello, Welcome to Micorosoft Q&A,

    Custom Audio does not work on UWP as indicted in the docs

    There are many reason cause this problem, During the testing there are many key points you need to know,
    Please make sure your audio available and the audio file build action is Content.
    The audio will play when notification show, please make suitable file size.
    and notification has type limit, please refer this document to chose which type you want use.

    Supported audio file types include...

    .aac
    .flac
    .m4a
    .mp3
    .wav
    .wma


    If the response is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    0 comments No comments

0 additional answers

Sort by: Most helpful