AVFoundation: Audio from AVAudioPlayer picked up during recording - ios

I am writing an app that plays an audio track for the user to listen to whilst recording from the camera and microphone (using headphones).
The audio track is played using AVAudioPlayer.
The camera/microphone is recorded using AVCaptureSession.
The output uses AVCaptureMovieFileOutput.
It all works perfectly on an iPhone 5 but my iPad 4 experiences an odd side effect. When playing back the recording from the iPad you can hear the audio track as if it has also been recorded. This is all done whilst using headphones and the audio is too quiet to be picked up by the microphone.
When testing on the iPhone only the audio from the mic is recorded, as expected. Both use the same code. Any ideas would be appreciated!!

In case anyone else is having the same problem. I couldn't solve it. Instead I used the setPreferredDataSource:error: method in AVAudioSession to use the device microphone instead of the one on the headset.

Related

Why don't hear music after recording in swift?

I'm making a karaoke application. If the headphones aren't plugged in, my app works fine. (my voice and background music record together). It is successful, but when I do the same way with headphone then I listen to the recording. I can't hear the background music, but I hear the voice clearly. I attached the code below I used:
https://github.com/genedelisa/AVFoundationRecorder
The issue is that when the headphones are plugged in, the mic is not able to pick up and record the audio, only your voice. Obviously, when the headphones are not plugged in, this is not an issue.
I would recommend that you combine the music and the voice recording after the voice is recorded if the user was using headphones. Suggestions on how to do that can be found on this post: How to merge two mp3 files iOS?
Also, to check if headphones are plugged in check out this post: Are headphones plugged in? iOS7

iOS 6 AVAudioSession issue

In my application I have made [audioSession setCategory:AVAudioSessionCategoryPlayback] to play audio in back ground and also to mute other audio play backs while playing song in my application. I am playing the audio using AVPlayer and also I have UIWebView for playing video in same Application. The issue arises when I play both video in web view and audio using AVPlayer. The music mixes in this case. Prior to iOS 6 when I rech same situation one audio pauses automatically and the mixing up does not occur. So kindly suggest some solutions.
Try to set
Required background modes -> App plays audio
in Info.plist.

Play game background music with iPod music using CocosDenshion

As you can suggest, I have a trouble =)
In the game I use CocosDenshion for playing both background music and sound effects. As far as I know and can see in the code, it uses AVAudioPlayer to play background music. The trouble is appeared when I try to launch my app with music from iPod library.
I set audio category to AmbientSound (tried setting both with AVAudioSession and C interface). If I then try to play game background track directly using AVAudioPlayer, it plays with iPod music in background without problems. But if try to play background music with SimpleAudioEngine, only iPod music is playing.
Can someone give an advice how to make CocosDenshion work in this case?

How to start playing a sound while iPod's screen is turned off?

I need to play a custom sound synthesized using AudioUnit on an iPod.
This sound shall be played after up to one hour of playing music from a playlist on the iPod (it is played using MPMusicPlayerController).
The issue is that everything works fine if the screen in on, however my custom sound doesn't play if the screen is off.
If the sound is already playing when the screen is turned off it keeps playing well. So I assume I am using the correct audio session category.
Could you give me any hint?
According to Apple's developer library:
AVAudioSessionCategoryPlayback or the equivalent
kAudioSessionCategory_MediaPlayback—Use this category for an
application whose audio playback is of primary importance. Your audio
plays even with the screen locked and with the Ring/Silent switch set
to silent.
(Also, check this table.)
It seems that setting the audio session category to AVAudioSessionCategoryPlayback or kAudioSessionCategory_MediaPlayback would automatically fix your problem.

Recording video with AVFoundation stops sound

The application I'm currently working on plays background sound by using AVFoundation and effect sounds using the Finch engine. Problem is when I try to record video with sound (i.e. add a audio input to the session) by using AVFoundation lower level classes all sounds suddenly stop. Also, on iOS 5, if I try to record a second video I get an error. If the video is recorded without audio everything is fine. Any ideas what the cause might be
Your audio session is being interrupted by the AVFoundation daemon. You need to set a non-exclusive audio session category to stop this happening.
See the Audio Session Cookbook section of the Audio Session Programming Guide.

Resources