Skip to content

Latest commit

 

History

History
67 lines (42 loc) · 2.77 KB

appnotificationbuilder_setaudioevent_1027247183.md

File metadata and controls

67 lines (42 loc) · 2.77 KB
-api-id -api-type
M:Microsoft.Windows.AppNotifications.Builder.AppNotificationBuilder.SetAudioEvent(Microsoft.Windows.AppNotifications.Builder.AppNotificationSoundEvent,Microsoft.Windows.AppNotifications.Builder.AppNotificationAudioLooping)
winrt method

Microsoft.Windows.AppNotifications.Builder.AppNotificationBuilder.SetAudioEvent(Microsoft.Windows.AppNotifications.Builder.AppNotificationSoundEvent,Microsoft.Windows.AppNotifications.Builder.AppNotificationAudioLooping)

-description

Sets the audio event and looping behavior for an app notification.

-parameters

-param appNotificationSoundEvent

A member of the AppNotificationSoundEvent enumeration specifying a system sound to play.

-param loop

A member of the AppNotificationAudioLooping enumeration specifying the looping behavior for the audio.

-returns

Returns the AppNotificationBuilder instance so that additional method calls can be chained.

-remarks

This method allows you to provide an consistent audio experience by specifying an audio event type, which uses standardized system sounds. You can specify a custom sound for an app notification by calling SetAudioUri.

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.

-see-also

-examples

The following example demonstrates setting an audio event in the XML payload for an app notification.

var notification = new AppNotificationBuilder()
    .AddText("Notification text.")
    .SetAudioEvent(AppNotificationSoundEvent.Alarm, 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-winsoundevent:Notification.Looping.Alarm' loop='true'/>
</toast>