Unable to prepareToPlay() only on release build

Having an issue playing songs fetched with MusicKit but only on release builds, ApplicationMusicPlayer.shared.prepareToPlay() throws "The operation couldn’t be completed. (MPMusicPlayerControllerErrorDomain error 6.)"

The authorization status is .authorized

The debug version of the app works perfectly.

Here is my project for the reference.

Thank you.

macOS 15.0.1, Xcode 16.0

Answered by hermanberd in 812055022

Solved: Since my project is a SwiftPM package, the release binary has to be manually codesigned so that MediaPlayer can work properly.

func addItemsToQueue<T>(
    items: MusicItemCollection<T>,
    at position: ApplicationMusicPlayer.Queue.EntryInsertionPosition
) async
where T: PlayableMusicItem {
    do {
        if player.queue.entries.isEmpty {
            player.queue = .init(for: items)
        } else {
            try await player.queue.insert(items, position: position)
        }
    } catch {
        await logger?.error(
            "Unable to add songs to player queue: \(error.localizedDescription)"
        )
        return
    }
    do {
        if !player.isPreparedToPlay {                
            await logger?.trace("Preparing player...")
            try await player.prepareToPlay()
        }
    } catch {
        await logger?.critical("Unable to prepare player: \(error.localizedDescription)")
    }
}

This is a snippet which produces this error.

For some insane reason it only works on release builds.

I am completely frustrated and there is no way to check what is going wrong inside the MusicKit library

Accepted Answer

Solved: Since my project is a SwiftPM package, the release binary has to be manually codesigned so that MediaPlayer can work properly.

Unable to prepareToPlay() only on release build
 
 
Q