I have an app that plays audio.
I'm trying to get all "edge cases" taken care of before app release.. no matter how slight.
As you may know... apps that play audio need to tell the IOS system how they intend to behave. Does their audio interrupt other apps? Do they mix with other apps? etc. etc.
So, the app needs to have its AVAudioSession code set up correctly... which I did according to Apple's docs:
import UIKit
import AVFoundation
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let audioSession = AVAudioSession.sharedInstance()
do {
try audioSession.setCategory(AVAudioSessionCategoryPlayback)
} catch {
print("Setting category to AVAudioSessionCategoryPlayback failed.")
}
do {
try audioSession.setActive(true)
} catch {
print("Setting AudioSession active failed.")
}
// Other project setup
return true
}
}
Imagine the following test:
1) Turn on bluetooth and connect to a bluetooth speaker.
2) Load a known-good app that plays audio while backgrounded, like Spotify. Play a song/audio and background it.
3) While the audio from APP B is still playing, load APP A (my app) and press any of the three buttons.
So... after executing step 3, what happens?
Well, that depends on what you are using... for example:
If you're just using the phone speaker (not an external Bluetooth speaker), everything works fine, as expected.
If you are using, for example, an ION Tailgater iPA77 Bluetooth speaker, everything works fine as expected.
BUT, if you are using, for example, an MTX MUDHSB-B Bluetooth speaker, then NOTHING HAPPENS when you press any of the three buttons... until you continue waiting and/or pressing buttons for a seemingly arbitrary amount of time (about 30 seconds)... then the sound will start to come through and behave normally.
How is it that one Bluetooth speaker would behave differently than another (presumably with respect to AVAudioSession)? Bluetooth is bluetooth, right? I guess not. Can anyone shed light on this?
Thanks.