AVAudioUnitSampler loading delay problem in iOS 11 but not iOS 10

Running on iOS 10 I am able to load a sample from file into an AVAudioUnitSampler on demand and it plays correctly.

However when I run the same code on iOS 11 the audio doesn't play. In order to get it to work I have to preload the audio.


Has something changed in iOS 11 that causes this to no longer work?


The is designed to play from a selection of about to 100 samples, some of them longer than others, so I can't load them all into memory in advance and thus need to load on demand.


I've tried this on iOS 11, 11.0.1 and 11.0.2.


Any suggestions?


This is my initial version (works on iOS 10 but not iOS 11):


var audioEngine:AVAudioEngine!
    var mixer:AVAudioMixerNode!
    var sampler:AVAudioUnitSampler!
  
    override func viewDidLoad() {
        super.viewDidLoad()
      
        audioEngine = AVAudioEngine()
        mixer = audioEngine.mainMixerNode
        mixer.volume = 1.0
      
        do {
            try audioEngine.start()
        } catch {
            print(error)
        }
      
        sampler = AVAudioUnitSampler()
      
        audioEngine.attach(sampler)
        audioEngine.connect(sampler, to: mixer, format: nil)
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        /
    }
    @IBAction func audio1Tapped(_ sender: Any) {
       if let audioPath = Bundle.main.url(forResource: "a73", withExtension: "wav") {
            do {
                try sampler.loadAudioFiles(at: [audioPath])
                sampler.startNote(60, withVelocity: 127, onChannel: 0)
            } catch {
                print(error.localizedDescription)
            }
        } else {
            print("Failed to find audio file")
        }

    }


The following works on iOS 11:


var audioEngine:AVAudioEngine!
    var mixer:AVAudioMixerNode!
    var sampler:AVAudioUnitSampler!

    override func viewDidLoad() {
        super.viewDidLoad()
     
        audioEngine = AVAudioEngine()
        mixer = audioEngine.mainMixerNode
        mixer.volume = 1.0
     
        do {
            try audioEngine.start()
        } catch {
            print(error)
        }
     
        sampler = AVAudioUnitSampler()
     
        audioEngine.attach(sampler)
        audioEngine.connect(sampler, to: mixer, format: nil)
     
        if let audioPath = Bundle.main.url(forResource: "a73", withExtension: "wav") {
            do {
                try sampler.loadAudioFiles(at: [audioPath])
            } catch {
                print(error.localizedDescription)
            }
        } else {
            print("Failed to find audio file")
        }
    }
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        /
    }
    @IBAction func audio1Tapped(_ sender: Any) {
        sampler.startNote(60, withVelocity: 127, onChannel: 0)
    }

Replies

could be this reason why ios 11 didn't play music with lots of car ?