2014-08-31 102 views
4

我在Windows Phone 8.1中遇到了一个吐司通知问题。 (确切版本:8.10.14157.200)。 我有一个应用程序向手机发送Toast通知。 我想用这个吐司通知播放自定义声音。 但是,Windows Phone只是播放其默认通知声音,而不是我自己的,我在吐司XML中指定。无法播放Windows Phone 8.1中的自定义音频wav文件Toast通知

<?xml version="1.0" encoding="UTF-8"?> 
<toast duration="long"> 
    <visual> 
     <binding template="ToastText02"> 
     <text id="1">Kainat</text> 
     <text id="2">Hi</text> 
     </binding> 
    </visual> 
<audio src="/Assets/hodor.wav" /> 
</toast> 

我试过以下音频元素没有成功。

<audio src="hodor.wav" /> 
<audio src="/hodor.wav" /> 
<audio src="/Assets/hodor.wav" /> 
<audio src="ms-appx:///Assets/hodor.wav" /> 
<audio src="ms-appx:///hodor.wav" /> 

我自己也尝试静音(只是为了验证,在XML作品的音频元素)

<audio silent="true"/> 

这个工作,被抑制的声音。

我在我的项目中添加了hodor.wav以及我的visual studio项目中的Assets文件夹。 也已将此wav资源的“复制到输出目录”选项设置为“始终复制”。

有什么我失踪?

+1

你有没有得到这个工作?如果是这样,怎么样? – DaveDev 2014-09-18 12:23:41

+0

我正面临同样的问题。在这里任何帮助家伙? – AbsoluteSith 2015-02-10 13:56:14

+0

这是我对这个问题的回答:http://stackoverflow.com/questions/33365202/windows-phone-8-1-toast-notification-not-playing-custom-sound/34186433#34186433如果有人正面临这个问题同样的问题 – ludesign 2015-12-09 18:41:06

回答

0

根据MSDN的文档,WNS中的音频标签不支持音频元素中的完全自定义声音(与WP8.0 GDR3上的WPNS相反)。您只能使用以下字符串来影响播放什么类型的通知(以及哪些内置于OS中)。

  • MS-winsoundevent:Notification.Default
  • MS-winsoundevent:Notification.IM
  • MS-winsoundevent:Notification.Mail
  • MS-winsoundevent:Notification.Reminder
  • MS-winsoundevent:通知.MS
  • ms-winsoundevent:Notification.Looping.Alarm
  • ms-winsoundevent:Notification.Looping.Alarm2
  • MS-winsoundevent:Notification.Looping.Alarm3
  • MS-winsoundevent:Notification.Looping.Alarm4
  • MS-winsoundevent:Notification.Looping.Alarm5
  • MS-winsoundevent:Notification.Looping.Alarm6
  • MS-winsoundevent:Notification.Looping.Alarm7
  • MS-winsoundevent:Notification.Looping.Alarm8
  • MS-winsoundevent:Notification.Looping.Alarm9
  • MS-winsoundevent:Notification.Looping.Alarm10
  • MS-winsoundevent:Notification.Looping.Call
  • MS-winsoundevent:Notification.Looping.Call2
  • MS-winsoundevent:Notification.Looping.Call3
  • MS-winsoundevent:Notification.Looping.Call4
  • ms-winsoundevent:Notification.Looping。Call5
  • MS-winsoundevent:Notification.Looping.Call6
  • MS-winsoundevent:Notification.Looping.Call7
  • MS-winsoundevent:Notification.Looping.Call8
  • MS-winsoundevent:Notification.Looping.Call9
  • MS-winsoundevent:Notification.Looping.Call10
3

@OliverUlm:MSDN说WP8.1可以使用自定义的声音。

根据MSDN页面here之一。它说:

“在Windows Phone 8.1,这个属性还可以包含指向本地音频文件,具有以下前缀之一:

ms-appx:/// 
ms-appdata:/// 

但是,我还没有想出如何播放声音

UPDATE:。

<?xml version="1.0" encoding="UTF-8"?> 
<toast> 
    <visual> 
    <binding template="ToastText02"> 
     <text id="1">Title</text> 
     <text id="2">Message</text> 
    </binding> 
    </visual> 
    <audio src="ms-appx:///Audio/Female/0530.mp3" /> 
</toast> 

这对我的作品

+0

你能帮助我如何在C#中做到这一点?我在使用C#时感到有些困惑。谢谢! – 2015-08-06 08:53:19

+0

@KishorBikramOli你能详细说明你在C#中做什么吗? Windows Phone Toast Notification需要一个XML对象才能工作。 – 2015-08-06 14:27:40

+0

我不想使用XML。我正在寻找这样的东西。我找到了解决方案。 XmlElement audio = toastXml.CreateElement(“audio”); audio.SetAttribute(“src”,“ms-appx:/// Sound \\ Alarm.mp3”); toastNode.AppendChild(audio); – 2015-08-07 10:16:07

0

尝试这个例子:

在代码

private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     ToastTemplateType toastTemplate = ToastTemplateType.ToastText02; 
     XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastTemplate); 
     XmlNodeList toastTextElements = toastXml.GetElementsByTagName("text"); 
     toastTextElements[0].AppendChild(toastXml.CreateTextNode("Test1")); 
     toastTextElements[1].AppendChild(toastXml.CreateTextNode("Test2")); 
     IXmlNode toastNode = toastXml.SelectSingleNode("/toast"); 
     XmlElement audio = toastXml.CreateElement("audio"); 
     string sound = "test1.mp3"; 
     if (sound != null) 
      audio.SetAttribute("src", "ms-appdata:///local/" + sound); 
     else 
      audio.SetAttribute("src", "ms-appx:///sounds/Bell.mp3"); 
     toastNode.AppendChild(audio); 
     ToastNotifier toastNotifier = 
     ToastNotificationManager.CreateToastNotifier(); 
     ToastNotification toastNotification = new ToastNotification(toastXml); 
     toastNotifier.Show(toastNotification); 
    } 

使用XAML: 在XMLFile1.xml:

 <?xml version="1.0" encoding="UTF-8"?> 
    <toast> 
     <visual> 
     <binding template="ToastText02"> 
     <text id="1">Test1</text> 
     <text id="2">Test2</text> 
     </binding> 
    </visual> 
    <audio src="ms-appdata:///local/test1.mp3"/> 
</toast> 

在MainPage.xaml.cs:

private void Button_Click(object sender, RoutedEventArgs e) 
    { 
     XmlDocument xmldoc = new XmlDocument(); 
     xmldoc.LoadXml(XDocument.Load("XMLFile1.xml").ToString()); 
     ToastNotifier toastNotifier = 
     ToastNotificationManager.CreateToastNotifier(); 
     ToastNotification toastNotification = new ToastNotification(xmldoc); 
     toastNotifier.Show(toastNotification); 
    }