[Question] How to vibrate indefinitely?
Closed this issue ยท 10 comments
How do I vibrate forever? Do I need my own loop or can I do something with the repeat
param in Vibrator.vibrate
?
any info on "repeat" would be great :/
@VictorUvarov @merelj I think it's not really possible to vibrate "forever". You can probably vibrate for 24 hours like that: Vibration.vibrate(duration: Duration(hours: 24).inMilliseconds);
.
@benjamindean thank you for the response.
somehow when I call
Vibration.vibrate(duration: const Duration(hours: 1).inMilliseconds);
it only vibrates for about 500ms and then stops.
I think, the question is actually "how do I make the phone vibrate for a long time using a pattern?".
i.e. 500ms vibration - 500 ms pause - 500ms vibration - 500ms pause and so on.
do i have to set [500, 500, 500, 500, ...] in pattern or is there an easier way (list might get a bit long if phone should vibrate for a minute or longer: 60s * 2 = 120 of those 500s)? ๐ค
@merelj What happens when you pass 0 as a repeat
argument?
I should say that _stopVibrating
is called a long time after vibration is over by another function, sorry for confusion ๐คฆ
i commented it out just in case and it did not help
@merelj What platform are you testing it on?
Thank you for your help ๐
I'm testing it on a real phone with android 10 QP1A.190711.020 (i believe it's 29'th version of android API)
Thank you for your help ๐
Turns out my problem was with ConnectionService on Android side of things.
If it helps anyone, the problem was that I should have set connection state to "ringing": otherwise it blocks phone vibration.
To answer the original question:
Vibration.vibrate(pattern: [500, 500], repeat: 0);
does exactly what I needed: vibrates the phone for 500ms, waits for 500ms and repeats the pattern ๐
I still think it would help a lot if repeat function was documented since repeat: 0
is pretty unexpected way to set repetitions count to infinity (if that is what it does; I can only say that I waited for about 2 minutes and it kept vibrating ๐คทโโ๏ธ ).
I tested Vibration.vibrate(pattern: [500, 500], repeat: 0);
on Android 11 (Google Pixel 2 XL) and iOS 14.0.1 (iPhone 11).
It only repeats on Android.
My current solution has been to just use a periodic timer
_timer = Timer.periodic(const Duration(milliseconds: 1500), (timer) {
Vibration.vibrate(pattern: [500, 1000], repeat: 0);
});
I also tested with and without CallKit on iOS