Me

import AVFoundation

var player: AVAudioPlayer?

func playBackgroundAudio() { do { try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) } catch { print("Audio session setup failed: (error)") }

if let url = Bundle.main.url(forResource: "background_music", withExtension: "mp3") {
    do {
        player = try AVAudioPlayer(contentsOf: url)
        player?.numberOfLoops = -1
        player?.play()
    } catch {
        print("Error playing audio: \(error)")
    }
}

}

playBackgroundAudio()

Thanks for taking the time to share your question here.

There is no question as I only see code on the post? It's also in code signing, so is your question about code signing?

Unfortunately, it hasn't received an answer yet. Here are a few suggestions that might help it attract more attention:

  • Provide more details: Expanding on your post to include any error messages, code snippets, steps you've already taken to troubleshoot, and the expected/actual outcomes would be very helpful.
  • Be specific about your technology stack: Clearly state the programming languages, frameworks, or tools you are using.
  • Check for duplicates: Before posting, make sure your question hasn't been asked before. You can use the search bar to find similar threads.

I'm sure someone in the community will be able to help once you have a chance to update your post.

It looks like you are setting up a Swift function to play looping background audio using AVFoundation?

If you want this music to continue playing when the app goes into the background code alone isn't enough. You must enable Background Modes.

Albert
  Worldwide Developer Relations.

Me
 
 
Q