Skip to content

Latest commit

 

History

History
88 lines (56 loc) · 2.72 KB

appnotificationbuilder_setaudiouri_1722288022.md

File metadata and controls

88 lines (56 loc) · 2.72 KB
-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)

-description

Sets the sound file and the audio looping behavior that is played when an app notification is displayed.

-parameters

-param audioUri

The URI of the audio file.

-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

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.

-see-also

-examples

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>