开发者

Detecting Vibration on a Table with the iPhone

开发者 https://www.devze.com 2023-02-19 13:59 出处:网络
is it possible to d开发者_如何转开发etect vibration on the iPhone? I\'m trying to figure out how to detect when the user smacks a desk or table when the phone is sitting on it. I remember reading some

is it possible to d开发者_如何转开发etect vibration on the iPhone? I'm trying to figure out how to detect when the user smacks a desk or table when the phone is sitting on it. I remember reading somewhere you could detect a smack on a wooden table using the mic and AVFoundation. Any ideas?

Thanks


if you go down the microphone route, something like this might do the trick:

//somewhere during setup call this line
[anAVAudioRecorder setMeteringEnabled:YES];

//then in a method used to poll the audioMeter
[anAVAudioRecorder updateMeters];
averagePower = [anAVAudioRecorder averagePowerForChannel:0];
if (averagePower > threshold ) {
    [musicPlayerClass play];
} 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号