通知声音Windows商店应用程序


 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);

所以我把这个代码从一个网页,它的工作,但有一个细节。它播放的声音不是我想要的……即使指定名称和资产,它看起来像从微软播放一些声音?谢谢!

显然这是windows 10中的一个bug,目前还没有解决方案。http://blogs.msdn.com/b/tiles_and_toasts/archive/2015/07/02/adaptive -和-互动-面包通知- windows - 10. - aspx

"……自定义音频不起作用。我们正在调查这个问题。这两个ms-appx和ms-appdata不能在Desktop上工作,只有ms-appdata可以工作在移动。"

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

支持的声音的完整列表可以在MSDN的这个文档中找到。

最新更新