Share via


AppNotificationBuilder.SetAudioUri Method

Definition

Overloads

SetAudioUri(Uri)

Sets the sound file that is played when an app notification is displayed.

SetAudioUri(Uri, AppNotificationAudioLooping)

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

SetAudioUri(Uri)

Sets the sound file that is played when an app notification is displayed.

public:
 virtual AppNotificationBuilder ^ SetAudioUri(Uri ^ audioUri) = SetAudioUri;
/// [Windows.Foundation.Metadata.Overload("SetAudioUri")]
AppNotificationBuilder SetAudioUri(Uri const& audioUri);
[Windows.Foundation.Metadata.Overload("SetAudioUri")]
public AppNotificationBuilder SetAudioUri(System.Uri audioUri);
function setAudioUri(audioUri)
Public Function SetAudioUri (audioUri As Uri) As AppNotificationBuilder

Parameters

audioUri
Uri Uri

The URI of the audio file.

Returns

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

Attributes

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"))
    .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>

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.

Applies to

SetAudioUri(Uri, AppNotificationAudioLooping)

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

public:
 virtual AppNotificationBuilder ^ SetAudioUri(Uri ^ audioUri, AppNotificationAudioLooping loop) = SetAudioUri;
/// [Windows.Foundation.Metadata.Overload("SetAudioUri2")]
AppNotificationBuilder SetAudioUri(Uri const& audioUri, AppNotificationAudioLooping const& loop);
[Windows.Foundation.Metadata.Overload("SetAudioUri2")]
public AppNotificationBuilder SetAudioUri(System.Uri audioUri, AppNotificationAudioLooping loop);
function setAudioUri(audioUri, loop)
Public Function SetAudioUri (audioUri As Uri, loop As AppNotificationAudioLooping) As AppNotificationBuilder

Parameters

audioUri
Uri Uri

The URI of the audio file.

loop
AppNotificationAudioLooping

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.

Attributes

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>

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.

Applies to