如何使Windows Phone震动并播放声音

来源:互联网 发布:树莓派3 ubuntu 16.04 编辑:程序博客网 时间:2024/06/05 06:48
 
这篇文章描述了如何使Windows Phone设备震动并播放声音。
简介
使用代码使windows phone震动是非常简单的。利用下面的两个方法使windows phone开始和停止震动。 VibrateController是在命名空间Microsoft.Devices里;

public void Vibrate(long durationSeconds)
        {
            VibrateController vibController = VibrateController.Default;
            TimeSpan ts = new TimeSpan(00, 00, durationSeconds);
  
            vibController.Start(ts);
        }
  
        public static void VibrateStop()
        {
            VibrateController vibController = VibrateController.Default;
            vibController.Stop();
        }

播放声音
为了播放声音文件,我们使用下面的函数,这个函数的soundFile参数值是已经包含在资源里的音频文件的路径。
1public void PlaySound(string soundFile)
2        {
3            using (var stream = TitleContainer.OpenStream(soundFile))
4            {
5                var effect = SoundEffect.FromStream(stream);
6                FrameworkDispatcher.Update();
7                effect.Play();                 
8            }
9        }

  
原创粉丝点击