Select Page

Whilst recently working on the menu for my game, I decided to add some code to play an audio loop in the background.

The code itself was pretty straight forward thanks to the SKAudioNode object provided by SpriteKit:

        //Start background music
        if let bgAudioUrl = Bundle.main.url(forResource: "JungleVibin", withExtension: "m4a") {
            let backgroundMusic = SKAudioNode(url: bgAudioUrl)
            backgroundMusic.autoplayLooped = true
        else {
            print("Music Error")

What I found when I ran the code on both the simulator and a device was that it always ended up in the else part of the statement, and it took me a little while to figure out a solution.

The audio file was definitely in the project and everything was building just fine, what I had failed to do was ensure the m4a file was added to the target membership for the app.

To remedy this, is was simply a case of selecting the audio file in the solution explorer and ticking the following box:

Target Membership Settings

After changing this one thing, I could compile and run and it worked as expected.

On a side note, the audio for the game is being worked on by the fantastic Félix of Canada. I’ve not really used Fiverr before, but I happened across his profile. He has produced excellent results so far and I’d highly recommend checking him out.

Until next time


%d bloggers like this: