Monitor iPhone mic

2020-08-01 06:10发布

问题:

I'm using SCListener to get the iPhone's volume, but I'd like to put an observer on the volume. So when it changes I can update the volume meter on the screen. But doing something like:

SCListener *listener = [SCListener sharedListener];
[listener addObserver:self 
           forKeyPath:@"peakPower" 
              options:NSKeyValueObservingOptionOld 
              context:NULL];

doesn't do the trick because peakPower isn't a variable. How would I put an observer on the function? Or how would a create a listener I could stop and start to keep track of the peak power in a variable I could put an observer on?

Thanks in advance for the help!

回答1:

SCListener is not Key Value Observer compliant. AFAIK, you have to poll for the values.



回答2:

Simply set up a repeating timer, and read the levels each time the timer fires.



标签: iphone