Why don't hear music after recording in swift? - ios

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

Related

iPhone playback quiet after microphone use

I'm using an AVSpeechSynthesizer in my app to synthesise text to speech and play it back on the iPhone's speakers. All works well.
After that I want to recognise the users speech and I'm using SwiftSpeech to do so. It uses SFSpeechRecognizer under the hood. Everything is good here too.
After that the output from speech synthesis (doing it just like before with AVSpeechSynthesizer) is really quiet.
And when the iPhone is connected to a bluetooth headset and it played back via the headphones fine, after doing the speech recognition, the audio output switched from the BT headset to the iPhone (again really quiet.)
I couldn't find anything about that online.
I don't know if sample code would be any helpful, let me know tho.

Does background audio work without .longFormAudio policy on WatchOS?

Does anyone know wether audio can be both recorded and played back in the background on the Apple Watch?
It's possible to playback audio in the background by adding the .longFormAudio policy on the audio session however this does not work with the .playAndRecord mode.
I'd like to be able to record audio from the device's microphone then play it back either through the device speaker or paired Bluetooth headphones.
The audio will also need to continue recording and playing if the user lowers their wrist and the watch display turns off.

iOS Force Audio Output only to headset jack

I want to direct iOS VoiceOver sound to headphone even if it's not plugged in.
In other words, while my app is open, VoiceOver sound (and other sounds played by me in app using AVSpeechUtterance etc.) should NEVER go to speakers, but should come out of headset, if connected.
Can anyone suggest something on this?
iOS devices will not power-up the headset jack for audio output unless a recognized (proper impedance, etc.) headset or headphone is currently plugged in to the jack.
VoiceOver audio will always go to the headset, if a valid one is plugged-in, and not over-ridden.
Apparently it's not possible to forcefully direct sound to headphone unless an accessory is plugged to headphone jack (which activates a physical switch to direct voice to headphone).
I've achieved my purpose using following code (in Swift) which directs VoiceOver and other sounds to phone speaker (from where we listen to phone calls) and silences loud speaker while my app is in foreground.
let session: AVAudioSession = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSessionCategoryPlayAndRecord)
try session.overrideOutputAudioPort(AVAudioSessionPortOverride.None)
try session.setActive(true)
} catch {
print("Couldn't override output audio port")
}

AVFoundation: Audio from AVAudioPlayer picked up during recording

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.

How to continue playing a youtube video at background when switch from my app back to home screen

Seems the default action for iOS 6 is to stop the video from playing after I switch to HOME screen. Then if I want to listen to the audio I have to go back to the app and press the 'Play' button again. I am using youtube API.
How can I continue playing the video when the application is in UIApplicationStateInactive and UIApplicationStateBackground. I just want to be able to listen to the audio even if I am on HOME screen or the screen is locked. Should I use a background thread or restart playing the video at the previous position as it was before turning the app inactive?
Take a look at the app 'Jasmine'. They managed to do something similar to what you are seeking. However, UIApplicationStateInactive/UIApplicationStateBackground will cause the video to pause. Double tapping the home button and then pressing the audio play button will cause the video's audio to resume without keeping the app active.
Take a look at the new iOS 7. You may have some luck there.
Inter-App Audio
Now your apps can make beautiful music together. With Inter-App Audio,
apps can register their audio streams to share with other apps. For
example, a series of apps could publish audio streams of instrument
tracks while another uses the combination of these streams to compose
a song. Inter-App Audio also provides for MIDI control of audio
rendering, remotely launching other registered Inter-App Audio apps
and more.

Resources