mattdryden
mattdryden

Reputation: 256

Phonegap record and playback simultaneously

I'm currently developing an iPhone/Android application in Phonegap and would like to record audio while playing back another track.

Now I know in Objective-C you can set the audio category to "AVAudioSessionCategoryPlayAndRecord" but since this is Phonegap and not a plain native objective-c app I'm not sure if it's possible for it to work or even where to put it as I think it needs to be in the phonegap core files somewhere>

Does anyone have any experience and/or ideas?

Upvotes: 0

Views: 560

Answers (2)

nachos
nachos

Reputation: 1056

This can be resolved by using a custom Objective C plugin, that sets the category of the AVAudioSession singleton instance to AVAudioSessionCategoryPlayAndRecord.

However there is a bug in the Cordova Media Plugin which complicates things, which can be worked around, if it is acceptable for you to start recording first, and then start playing the media.

If not, I have resolved this issue, and posted an answer here, where you can find more details:

Record and play simultaneously on iOS (Phonegap build)

Upvotes: 1

mattdryden
mattdryden

Reputation: 256

In case anyone else wants to know the answer to this, I managed to sort this issue out by recompiling Cordova/Phonegap (1.7.0 but 2.0 should be similar) with a tweak.

To tweak it I modified CDVSound.m, changing line 482 to

[self.avSession setCategory:AVAudioSessionCategoryPlayAndRecord error:nil];

And re-compiled and then used in my project.

Upvotes: 1

Related Questions