Reputation: 5843
I found a following issue of vibration device on Windows Phone 8.1 XAML application.
The code
var vibrationDevice = VibrationDevice.GetDefault();
vibrationDevice.Vibrate(TimeSpan.FromMilliseconds(50));
The first time when it's called, the vibration starts and doesn't stop until the next call. The following calls works correct - phone vibrates for short time and stops.
It reproduces on Lumia 920 at 100% calls and at Lumia 930 at 1% of calls. It reproduces on WP 8.0 and WP 8.1
Upvotes: 2
Views: 154
Reputation: 3324
This is a bug in the framework. What I use is to cancel it in a task after a delay which is the same as the vibration duration:
private const int DefaultVibrationDuration = 20;
if (this.EnableVibration)
{
VibrationDevice.GetDefault().Vibrate(TimeSpan.FromMilliseconds(DefaultVibrationDuration));
// Run task to cancel vibration (this is an error in phone framework where the vibration does
// not stop after running the first time)
Task.Run(async () =>
{
await Task.Delay(DefaultVibrationDuration);
VibrationDevice.GetDefault().Cancel();
});
}
Upvotes: 1