question

jcardif254 avatar image
1 Vote"
jcardif254 asked jcardif254 action

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

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();
windows-uwp
· 7
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

During the testing, it could work with custom audio toast, please check if your audio file stored in the above path. And please check if above ToastNotificationSound is too large.

0 Votes 0 ·

The file is in the assets folder in a subfolder called Audio. And the file size is 280 kB, but stull doesn't work while testing locally, is there a particular path that I am supposed to store the file?

0 Votes 0 ·

Please make sure it's build action is Content.

0 Votes 0 ·

Does it work, do you have any updates?

0 Votes 0 ·
Show more comments

1 Answer

NicoZhu-MSFT avatar image
0 Votes"
NicoZhu-MSFT answered

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.



5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.