15 Replies
      Latest reply: Oct 15, 2016 11:15 AM by pasifus RSS
      Song Zhang Level 1 Level 1 (0 points)

        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)