iosaudiobluetoothavaudiosessionspeaker

Why would different bluetooth speakers behave differently with respect to AVAudioSession (IOS)


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:

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.


Solution

  • Sound like a problem with the speaker somehow... did you try the same scenario with 2 apps that are not yours? For example Spotify and Apple Music?