【问题标题】:change default sound of toast notification for windows phone 8.1 app development更改 Windows Phone 8.1 应用程序开发的 toast 通知的默认声音
【发布时间】:2015-08-04 11:22:02
【问题描述】:

我正在使用以下代码为 Windows phone 8.1 应用程序实现 toast 通知。我必须将默认声音更改为 Assets 文件夹中的声音。谁能帮帮我?

ToastTemplateType toastType = ToastTemplateType.ToastText02;

                XmlDocument toastXml = ToastNotificationManager.GetTemplateContent(toastType);

                XmlNodeList toastTextElement = toastXml.GetElementsByTagName("text");

                toastTextElement[0].AppendChild(toastXml.CreateTextNode("WeCare says: "));
                toastTextElement[1].AppendChild(toastXml.CreateTextNode(initialTime + " seconds left"));

                IXmlNode toastNode = toastXml.SelectSingleNode("/toast");
                XmlElement audio = toastXml.CreateElement("audio");
                // audio.SetAttribute("src", "/Assets/N.mp3");
                ((XmlElement)toastNode).SetAttribute("duration", "long");

                //((XmlElement)toastNode).SetAttribute("loop", "true");

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

【问题讨论】:

    标签: c# windows-phone-8.1


    【解决方案1】:

    确保您在 XML 中指定的文件存储在正确的位置。 Toast with sound 仅适用于 Windows Phone 8 Update 3 及更高版本。还要确保声音文件的长度小于 10 秒。

    见这个例子here

    确保您对 toast 通知使用正确的 xml 格式

    public void ShowToastWithCloudService(bool useCustomSound, bool useWavFormat, bool doSilentToast)
    {
        StringBuilder toastMessage = new StringBuilder();
        toastMessage.Append("<?xml version=\"1.0\" encoding=\"utf-8\"?><wp:Notification xmlns:wp=\"WPNotification\"><wp:Toast>");
        toastMessage.Append("<wp:Text1>Toast Title</wp:Text1>");
        toastMessage.Append("<wp:Text2>Toast Content</wp:Text2>");
        if ((IsTargetedVersion) && (useCustomSound))
        {
            if (useWavFormat)
            {
                toastMessage.Append("<wp:Sound>MyToastSound.wav</wp:Sound>");
            }
            else
            {
                toastMessage.Append("<wp:Sound>MyToastSound.mp3</wp:Sound>");
            }
        }
        else if ((IsTargetedVersion) && (doSilentToast))
        {
            toastMessage.Append("<wp:Sound Silent=\"true\"/>");
        }
        toastMessage.Append("</wp:Toast></wp:Notification>");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      相关资源
      最近更新 更多