-api-id | -api-type |
---|---|
M:Microsoft.Windows.AppNotifications.Builder.AppNotificationBuilder.SetAudioUri(Windows.Foundation.Uri,Microsoft.Windows.AppNotifications.Builder.AppNotificationAudioLooping) |
winrt method |
Microsoft.Windows.AppNotifications.Builder.AppNotificationBuilder.SetAudioUri(Windows.Foundation.Uri,Microsoft.Windows.AppNotifications.Builder.AppNotificationAudioLooping)
Sets the sound file and the audio looping behavior that is played when an app notification is displayed.
The URI of the audio file.
A member of the AppNotificationAudioLooping enumeration specifying the looping behavior for the audio.
Returns the AppNotificationBuilder instance so that additional method calls can be chained.
The following audio file types are supported:
- .aac
- .flac
- .m4a
- .mp3
- .wav
- .wma
The following audio file sources are supported:
- ms-appx:///
- ms-resource
The following audio file sources are unsupported:
- ms-appdata
- Internet URLs, such as http://, https://
- Absolute file paths, such as C:/, F:/, etc.
You can specify a sound event, which plays a system-defined sound, by calling SetAudioEvent.
For guidance on using the AppNotificationBuilder APIs to create the UI for app notifications, see App notification content.
For reference information about the XML schema for app notifications, see App notification content schema.
The following example demonstrates setting an audio URI in the XML payload for an app notification.
var notification = new AppNotificationBuilder()
.AddText("Notification text.")
.SetAudioUri(new Uri("ms-appx:///Audio/NotificationSound.mp3"), AppNotificationAudioLooping.Loop)
.BuildNotification();
AppNotificationManager.Default.Show(notification);
The resulting XML payload:
<toast>
<visual>
<binding template='ToastGeneric'>
<text>Notification text.</text>
</binding>
</visual>
<audio src='ms-appx:///Audio/NotificationSound.mp3'/>
</toast>