My app lets users select an audio recording from their iTunes media library, then saves the media ID for later playback. From the media ID, I can use MPMediaQuery
to get an MPMediaItem
, then get the recording URL:
let recordingURL = mediaItem?.value(forProperty: MPMediaItemPropertyAssetURL) as? URL
From the URL, I create an AVAudioFile
that I can give to an AVAudioPlayerNode
for playback:
do {
let audioUnitFile = try AVAudioFile(forReading: recordingURL)
} catch let error {
NSLog("error loading AVAudioFile: " + error.localizedDescription)
}
This all works fine on iOS. On Mac Catalyst, I can get a valid URL (I can see it's correct when inspecting it in the debugger), but the AVAudioFile:forReading
function throws this error:
ExtAudioFile.cpp:193:Open: about to throw -54: open audio file
[avae] AVAEInternal.h:109 [AVAudioFile.mm:134:AVAudioFileImpl: (ExtAudioFileOpenURL((CFURLRef)fileURL, &_extAudioFile)): error -54
error loading AVAudioFile: The operation couldn’t be completed. (com.apple.coreaudio.avfaudio error -54.)
I checked the Privacy settings in the Mac Settings app, and my app has permission to access the music library. What else can I check? What does error -54 mean? Is this supported with Mac Catalyst apps?
I'm using Xcode 12.5.1 on macOS 11.4.