jpsim / JPSVolumeButtonHandler

JPSVolumeButtonHandler provides an easy block interface to hardware volume buttons on iOS devices. Perfect for camera apps!
MIT License
333 stars 90 forks source link

Weird bug when used at the same time as an AVCaptureSession #7

Open ndbroadbent opened 9 years ago

ndbroadbent commented 9 years ago

Please see my StackOverflow post for details: http://stackoverflow.com/questions/29312178/cant-call-startrecordingtooutputfileurl-more-than-once-on-instance-of-avcapture

I think JPSVolumeButtonHandler might not be cleaning up after itself properly. If I initialize it once, then I can record videos fine. But if I set it to nil and it deallocates (when my view disappears), and then I initialize it again, I can't record videos anymore (Using AVCaptureMovieFileOutput#startRecordingToOutputFileURL).

ndbroadbent commented 9 years ago

Aha, the problem was that JPSVolumeButtonHandler is calling setCategory and setActive on an AVAudioSession, which screwed up my video recording, maybe because I was also recording the audio from the microphone. Also, I think you should use self.session = [AVAudioSession sharedInstance]; instead of instantiating a new one, since it's a singleton object.

Do you know if calling setCategory and setActive is really necessary? My app is already calling them, but I commented out all the calls in my app, as well as in JPSVolumeButtonHandler, and I could still capture the volume buttons without any issues.

ndbroadbent commented 9 years ago

Oh, the sharedInstance thing was already fixed in this commit. Sorry, I was looking at the latest code I found on Cocoapods, which doesn't seem to be updated yet.

dirkmcpherson commented 9 years ago

@ndbroadbent did commenting out setCategory and setActive work for you? I am running into the exact same problem on the most recent version (Jan 2015), when I modify those calls I can no longer use the volume buttons.