I myself fiddled in the dark, but I think this may be due to some limitation of fast playgrounds. Consider this code:
#!/usr/bin/swift import Cocoa import AVFoundation var error: NSError? println("Hello, Audio!") var url = NSURL(fileURLWithPath: "/Users/somebody/myfile.mid") // Change to a local midi file var midi = AVMIDIPlayer(contentsOfURL: url, soundBankURL: nil, error: &error) if midi == nil { if let e = error { println("AVMIDIPlayer failed: " + e.localizedDescription) } } midi.play(nil) while midi.playing { // Spin (yeah, that bad!) }
If you run this quick script in the terminal, it works fine and plays a MIDI file, but if you run the code on the playground, you will get
AVMIDIPlayer error: operation could not be completed. (error com.apple.coreaudio.avfaudio -1.)
On the plus side, the ability to run it in the terminal shows that the code really works.
source share