自定义通知声音未播放 windows 通用应用程序 8.1
custom notification sound is not playing windows universal app 8.1
我想在收到通知时播放自定义声音,但播放的不是自定义声音,而是默认声音。这里出了什么问题。甚至正确路径上的音频。
public void AddNotification(int t, String date,String idPrefix)
{
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
DateTime dueTime = DateTime.Now;
string period = String.Empty;
switch (t)
{
case 0:
period = "15min";
dueTime = GetNotificationTime(date, dueTime, 15);
break;
case 1:
period = "30min";
dueTime = GetNotificationTime(date, dueTime, 30);
break;
case 2:
period = "1hr";
dueTime = GetNotificationTime(date, dueTime, 60);
break;
default: break;
}
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("show time"));
toastTextElements[1].AppendChild(toastXml.CreateTextNode("Watch show in " + period));
//XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
//((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/CameraSelected.png");
//((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "Camera Selected");
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("launch", "LandingPage.xaml");
XmlElement audio = toastXml.CreateElement("audio");
audio.SetAttribute("src", "ms-appx:///Assets/Guitar.aifc");
toastNode.AppendChild(audio);
//launch tost immediatly
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
我在这里做错了什么。谁能指导我实施。
我想出了解决办法
不支持aifc文件。我已经将声音文件转换为 wav,现在它工作正常
我想在收到通知时播放自定义声音,但播放的不是自定义声音,而是默认声音。这里出了什么问题。甚至正确路径上的音频。
public void AddNotification(int t, String date,String idPrefix)
{
ToastTemplateType toastTemplate = ToastTemplateType.ToastText02;
XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate);
DateTime dueTime = DateTime.Now;
string period = String.Empty;
switch (t)
{
case 0:
period = "15min";
dueTime = GetNotificationTime(date, dueTime, 15);
break;
case 1:
period = "30min";
dueTime = GetNotificationTime(date, dueTime, 30);
break;
case 2:
period = "1hr";
dueTime = GetNotificationTime(date, dueTime, 60);
break;
default: break;
}
XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text");
toastTextElements[0].AppendChild(toastXml.CreateTextNode("show time"));
toastTextElements[1].AppendChild(toastXml.CreateTextNode("Watch show in " + period));
//XmlNodeList toastImageAttributes = toastXml.GetElementsByTagName("image");
//((XmlElement)toastImageAttributes[0]).SetAttribute("src", "ms-appx:///assets/CameraSelected.png");
//((XmlElement)toastImageAttributes[0]).SetAttribute("alt", "Camera Selected");
IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
((XmlElement)toastNode).SetAttribute("launch", "LandingPage.xaml");
XmlElement audio = toastXml.CreateElement("audio");
audio.SetAttribute("src", "ms-appx:///Assets/Guitar.aifc");
toastNode.AppendChild(audio);
//launch tost immediatly
ToastNotification toast = new ToastNotification(toastXml);
ToastNotificationManager.CreateToastNotifier().Show(toast);
}
我在这里做错了什么。谁能指导我实施。
我想出了解决办法
不支持aifc文件。我已经将声音文件转换为 wav,现在它工作正常