通知声音Windows应用商店

时间:2013-06-12 03:28:41

标签: windows-store-apps

 ToastTemplateType toastType = ToastTemplateType.ToastImageAndText02;
           XmlDocument toastXML = ToastNotificationManager.GetTemplateContent(toastType);
           XmlNodeList toastText = toastXML.GetElementsByTagName("text");
           XmlNodeList toastImages = toastXML.GetElementsByTagName("image");
           toastText[0].InnerText = "Funny cat";
           toastText[1].InnerText = "This cat looks like it's trying to eat your face.";
           ((XmlElement)toastImages[0]).SetAttribute("src", "ms-appx:///Assets/washer.png");
           ((XmlElement)toastImages[0]).SetAttribute("alt", "Scary Cat Face");

           //This is the options code, which is all optional based on your needs.
           IXmlNode toastNode = toastXML.SelectSingleNode("/toast");

           ((XmlElement)toastNode).SetAttribute("duration", "long");

           XmlElement audioNode = toastXML.CreateElement("audio");

           audioNode.SetAttribute("src", "ms-appx:///Assets/beep.wav");

           //Must be used when looping audio has been selected.
           audioNode.SetAttribute("loop", "true");
           toastNode.AppendChild(audioNode);

           //You can append any text data you would like to the optional
           //launch property, but clicking a Toast message should drive
           //the user to something contextually relevant.
           ((XmlElement)toastNode).SetAttribute("launch", "<cat state='angry'><facebite state='true' /></cat>");

           ToastNotification toast = new ToastNotification(toastXML);
           ToastNotificationManager.CreateToastNotifier().Show(toast);

所以我从网页上获取了这段代码并且它有效,但有一个细节。它播放的声音不是我想要播放的声音......即使指定名称和资产,它看起来像是从微软播放一些声音?谢谢!

2 个答案:

答案 0 :(得分:1)

显然这是Windows 10中的一个错误,目前还没有解决方案。 http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/07/02/adaptive-and-interactive-toast-notifications-for-windows-10.aspx

  

&#34; ...自定义音频不起作用。我们正在调查此问题。都   ms-appx和ms-appdata不在桌面上工作,只有ms-appdata工作   在移动设备上。&#34;

答案 1 :(得分:0)

Toast通知只能播放一组固定的系统提供的声音 - 例如ms-winsoundevent:Notification.Mail。如果未指定特定声音,或者提供了无效的src,则将播放默认声音。

支持声音的完整列表可在this documentation on MSDN中找到。