respond to bluetooth headsets play/pause events - ios

I've been able to respond to wired headphone events (play/pause) using MPRemoteCommandCenter, however this doesn't work for airpods.
Anything different I need to do to observe airpods or bluetooth headphones play/pause/button events? Thanks!

Related

How to detect mute button event is triggered in iOS

Neither I don't want to mute or unmutes iPhone nor I want to detect that it muted or unmuted, I just want to know, how can I detect mute button trigger event whether it is on to off or off to on?
There is no native iOS API to detect if the mute switch is enabled/disabled on a device.
The general principle to check if the device is muted is to play a short sound and detect the length it took to play. From this length, we can determine if it was muted or not. Check https://github.com/akramhussein/Mute or https://github.com/moshegottlieb/SoundSwitch

iOS - AVAudioSession Route Change Notification not work as expected

I have a app that can play sound. it works fine in usually. However when I Repeatedly disconnect and connect the Bluetooth headset, iPhone status bar shows the Bluetooth headset has been connected, and sound play is not in Bluetooth output route(maybe built-in receiver or speaker).
In my code, the last few disconnect and connect have not been notified from AVAudioSession Route Change Notification. And I get current output route from [[[[AVAudioSession sharedInstance] currentRoute] outputs] firstObject] is also not the bluetooth output.
Is this an issue of iOS? and Can I handle it with code? cause I want to play sound in a Bluetooth route in above case.
Thanks!!!

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 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")
}

Detect hardware mute button

How to mute application sound when hardware mute button on iPhone and iPad is on.I want to detect that whenever hardware mute button is turned on and off my application sound will be turned on and off.
You need not listen to the event, just use appropriate audio session category.
AVAudioSessionCategoryAmbient or AVAudioSessionCategorySoloAmbient

Resources