簡體   English   中英

更改Windows Phone 8.1應用程序開發的默認Toast通知聲音

[英]change default sound of toast notification for windows phone 8.1 app development

我正在使用以下代碼為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);

確保您在XML中指定的文件存儲在正確的位置。 帶有聲音的敬酒僅在Windows Phone 8 Update 3和更高版本上有效。 另外,請確保聲音文件的長度少於10秒。

在這里看到這個例子

確保您使用正確的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>");
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM