Get HTML5 deviceMotion events fire at a higher rate
Asked Answered
B

0

8

I am currently developing mobile web apps that make an extensive use of the deviceOrientation and deviceMotion HTML5 APIs. In most mobile browsers, the event fires every 50 millisecond which is too slow for the precision I need: is there a way to get the motion data at a higher rate?

I looked at the W3C DeviceOrientation Event Specification, and I noticed that the firing rate was given by the interval property of the devicemotion event, which is unfortunately readonly (plus, I am not sure whether this is only an indicator of the refresh rate as implemented by the browser, or if this actually sets the refresh rate of the browser). I saw that the initAccelerometerEvent method might allow to change this value, but I couldn't find how to use it directly in my Javascript code.

Alternatively, I thought we might be able to get the current value of the accelerometers / gyroscope: if such a method existed, we could use it in a setInterval method so that we would set the refresh rate we want. Unfortunately, I couldn't find such a method.

So, any advice to have the motion values at a higher rate would be most welcome. Thank you very much for your help!

Bejarano answered 25/11, 2014 at 10:19 Comment(3)
Just curiosity: 50 millis means 20 times per second, I can't see how you can move an smartphone fast enough to feel that sensor too slow and, at the same time, need so much precision.Zebec
We are developing web apps where the audio reacts to motion. Human perception accepts a ~20ms latency between a visual / gestural cue and the corresponding audio. Above that threshold, it doesn't feel “right”. Say we want to trigger a snare sound when the user strikes his phone: with the 50 ms rate, there is a perceptible latency between the gesture and the triggered sound, and this becomes really annoying in the long run. Plus, there are other things (e.g. that require the past 5 values) that we simply can't implement with a 50 ms refresh rate. 10 ms like on native apps would be ideal.Bejarano
in my phone I checked and the interval reads "16" which means 62.5 times per second.Langan

© 2022 - 2024 — McMap. All rights reserved.