Problems using AudioKit with ReplayKit

520 views
Skip to first unread message

Marcus Milne

unread,
Nov 27, 2015, 5:25:39 AM11/27/15
to AudioKit Users Group
I'm using AudioKit for iOS (Swift 2) so I can analyse a singer's pitch.  So with this app I'm using the microphone and the analyser.  However, I also have a button so you can record the whole interaction as a video via ReplayKit (new iOS framework for video/audio screen capturing).  This does actually work.  The problem is AudioKit stops running exactly when the view controller for the video previewer has been dismissed.  It runs while I'm recording.  When I stop recording the video preview opens up.  I can playback the video and see that it did indeed capture everything.  AudioKit is still running even while this video view controller is up (I can tell from console logs).  Its only when I touch "CANCEL" or "SAVE" that AudioKit stops running.  Weird thing is when I check AKManager.sharedInstance.isRunning it returns true.  I've also tried restarting the microphone and analyser.  I've tried a whole number of different combinations of stopping and restarting things but nothing seems to bring it back to life again.  Does anyone know how I can prevent it stopping in the first place?  Or if I can't, is there a way I can completely restart it?

Aurelius Prochazka Ph.D.

unread,
Nov 28, 2015, 12:59:37 AM11/28/15
to AudioKit Users Group
I hadn't heard of ReplayKit but I just checked it out and it looks pretty cool!  I'm guessing that you need to start AudioKit from something that does not go away, like a view might.  Perhaps you can set up a conductor singleton that manages AudioKit and keeps it alive while views are changing?  It is weird that isRunning is still true.  It doesn't sound like you're far from figuring out a solution, just need that magic combination.

Aure

Marcus Milne

unread,
Nov 28, 2015, 3:32:06 AM11/28/15
to AudioKit Users Group
I was about to explain to you that the AudioKit view doesn't go away, but another view covers it, then disappears, then I realised when the other view disappears, it causes the "viewDidAppear" function to run again on the AudioKit view.  I had some AudioKit initialisation code there which ended up getting run a second time and screwed things up.  So all I did was move all the init code into "viewDidLoad" and problem solved!

Kunal Verma

unread,
Jun 16, 2017, 3:32:13 PM6/16/17
to AudioKit Users Group
Hi
Am facing a similar issue with ReplayKit and Audiokit. Strange thing is that the issue occurs only on iPhone 7. When I start screen recording with ReplayKit and on the side , want to play sound with AudioKit singleton player, the Audiokit doesn't make any sound and the AudioKit.engine.isRunning is true for 2 times then goes false. 
On my iPhone 5s and iPad Air 2, this issue does not occur. On those devices,  the app works flawless. 
I have tried different session category of audio like multiroute, playback , playandrecord but multiroute works fine on iphone 5s and ipad air 2 but not on iphone7. 

Any help would be appreciated.

Thanks
Kunal

Dave O'Neill

unread,
Jun 18, 2017, 12:01:09 AM6/18/17
to AudioKit Users Group
If you share a test project where the issue can be re-created I'll take a look.

Kunal Verma

unread,
Jun 18, 2017, 3:22:38 AM6/18/17
to AudioKit Users Group
Hi Dave

Thanks for the reply. I have created the test project. You can download it here
In this example project as well ,the issue arises only on iphone 7. Not on my iphone 5s. The audiokit goes isRunning false after 1 or multiple time starting recording.
Can it be due to the reason iphone 7 has stereo speakers? I am not sure. 
also am recreating audiokit and doing everything after recording starts in my main project. That works fine but there is click sound after recording 4-6 times when starting recording. The sound is due to audiokit being remade and all the initialization happening again.

Best,
Kunal

Kunal Verma

unread,
Jun 20, 2017, 2:45:11 AM6/20/17
to AudioKit Users Group
Have managed to solve this issue with a hackish solution. Found with solution here and used it as per my needs.
Adding these lines below before calling audio.start() and stuff. 
The again calling these two lines before starting recording. And setting set category with aksettings as .multiroute. But am not sure if it will work with .defaulttospeakers or .mixwithothers.

  AudioOutputUnitStop((AudioKitSingleton.sharedInstance?.AudioKitvar.engine.inputNode?.audioUnit)!)

        AudioUnitUninitialize((AudioKitSingleton.sharedInstance?.AudioKitvar.engine.inputNode?.audioUnit)!)

        

In my project, am also checking for .isrunning, and if .isrunning goes false, the recording takes more time with resetting up audiokit and plays the audio again. But that only happens like very rarely. 1 in 50. And not like before wherein it went true and still did not play sound.


Dont know if that will work with ipad pro as they also got stereo speakers. With this it works on my iphone 5s and ipad air 2.

Reply all
Reply to author
Forward
0 new messages