AVMIDIPlayer DLSBankManager::AddBank: Bank load failed

When I use AVMIDIPlayer to play a MusicSequence with only one note message. Most of times it works fine but sometimes it has no sound and logged as below:

DLSBankManager::AddBank: Bank load failed
Error Domain=com.apple.coreaudio.avfaudio Code=-10871 "(null)"

It works well on iOS9, but when i test it on iOS10 it runs into this issue. I'm sure that the sf2 sound bank file url is set properly. I paste the code as below:

func playAVMIDIPlayerPreview(_ musicSequence:MusicSequence) {
    
        guard let bankURL = Bundle.main.url(forResource: "FluidR3 GM2-2", withExtension: "sf2") else {
            fatalError("soundbank file not found.")
        }
    
        var status = OSStatus(noErr)
        var data:Unmanaged<CFData>?
        status = MusicSequenceFileCreateData (musicSequence,
                                              MusicSequenceFileTypeID.midiType,
                                              MusicSequenceFileFlags.eraseFile,
                                              480, &data)
    
        if status != OSStatus(noErr) {
            print("bad status \(status)")
        }
    
        if let md = data {
            let midiData = md.takeUnretainedValue() as Data
            do {
                try self.midiPlayerPreview = AVMIDIPlayer(data: midiData, soundBankURL: bankURL)
         
            } catch let error as NSError {
           
                print("Error \(error)")
            }
            data?.release()
        
            self.midiPlayerPreview?.play({ () -> Void in
                self.midiPlayerPreview = nil
                self.musicSequencePreview = nil
            })
        }
    
    }


The error is occur on this line:

try self.midiPlayerPreview = AVMIDIPlayer(data: midiData, soundBankURL: bankURL)

Accepted Reply

It appears that the workaround is to add the line:


errno = 0;


just before the call that fails. You may need to add #import <sys/errno.h> as well.


-DS

Replies

Could you clarify what you mean by "most of the time it works fine"? Does it mostly work fine under iOS10, or does it never work under iOS10? Does it always work under iOS9? Are you always using identical MIDI and bank files in all these cases?


Thanks.


-DS

Are you running this in the Simulator? If so, I just diagnosed this issue for another developer: The "access()" function which checks sandbox permissions for files is returning -54 (access denied) for some resource files being read in via apps running in the simulator -- but it does not do this every time (for me it did it on the first attempt to access a given URL).


-DS

Sorry, I did not describe clearly. I mean it works well and never run to this error on iOS9. But on iOS10, somtimes it has no sound and log as below:

DLSBankManager::AddBank: Bank load failed
Error Domain=com.apple.coreaudio.avfaudio Code=-10871 "(null)" 


And I am running it in a iPhone6 real device with iOS10 rather than a simulator.

Thanks very much for helping me.

Yes, I used the same bank file in all the cases. But the MIDI data may be different each time.

I am having this same error under iOS 10 with AVAudioUnitSampler with AVAudioSequencer. My code has been working perfectly until iOS10. This only happens every so often. So if i run the engine and play it's fine but if i stop the engine and try to restart it and load the files again a few times eventually i will run into this error and i will only hear a sine wave sound. coming from the AVAudioUnitSampler. If I stop the engine again after i get this error and try to play it again then it will work again but after a few times of doing this i will run into this error again



2016-09-21 08:46:09.290103 [593:120739] 155: DLSBankManager::AddBank: Bank load failed

2016-09-21 08:46:09.290156 [593:120739] 486: DLS/SF2 bank load failed

2016-09-21 08:46:09.290860 [593:120739] [central] 54: ERROR: [0x1b0064c40] >avae> AVAudioUnitSampler.mm:150: -[AVAudioUnitSampler loadInstrumentAtURL:error:]: error -10871

The name of the Fluid soundfont has a capitalized extension when you download it. Did you rename it?


    guard let bankURL = Bundle.main.url(forResource:"FluidR3 GM2-2", withExtension: "SF2") else {

Yes, I am sure the url is right and I montioned "Most of times it works fine". If the url is wrong, it will crash every time.

Any update on this

Hey Gene!


I follow your code a lot. I'm experiencing this same issue do you have any advice?

Hi,


Unfortunately, I do not have any progress on it. Do you find anything helpful?

Recently I found that play a sound after showing a UIAlertController will cause this issue for sure.

The issue has been diagnosed. This will be fixed in a future release. Thank you for reporting this.


-DS

Thanks very much for your reply.

It appears that the workaround is to add the line:


errno = 0;


just before the call that fails. You may need to add #import <sys/errno.h> as well.


-DS

I have the same problem