wp8应用在cordova下关于navigator.notification.beep的问题

打开org.apache.cordova.dialogs插件下的Notification.cs文件

将beep方法修改为:


public void beep(string options)
        {
            string[] args = JSON.JsonHelper.Deserialize<string[]>(options);
            int times = int.Parse(args[0]);

            string resourcePath = BaseCommand.GetBaseURL() + "Plugins/org.apache.cordova.dialogs/notification-beep.wav";

            StreamResourceInfo sri = Application.GetResourceStream(new Uri(resourcePath, UriKind.Relative));

            if (sri != null)
            {
                SoundEffect effect = SoundEffect.FromStream(sri.Stream);
                SoundEffectInstance inst = effect.CreateInstance();
                
                //添加的代码
                if (times == 0)
                {
                    inst.Volume = 0.0f;
                }

                ThreadPool.QueueUserWorkItem((o) =>
                {
                    // cannot interact with UI !!
                    do
                    {
                        inst.Play();
                        Thread.Sleep(effect.Duration + TimeSpan.FromMilliseconds(100));
                    }
                    while (--times > 0);

                });

            }

            // TODO: may need a listener to trigger DispatchCommandResult after the alarm has finished executing...
            DispatchCommandResult();
        }

上面代码中有个添加代码的注释,就是设置蜂鸣音量的。

我们可以在应用启动后首先使用navigator.notification.beep(0)来初始化蜂鸣。

这样以后调用navigator.notification.beep就不会引起蜂鸣延迟了。



你可能感兴趣的:(windows,Cordova,PhoneGap,8,phone)