I,m creating a app the use a lot of sfx and background music. But i can't find the best way to inherite this type of data through View Controllers. Do i have to initialize my audios in every view controller? But what if i want to stop a music that started in a preview VC?
This is the code that i'm using:
do {
// Music BG
let resourcePath = NSBundle.mainBundle().pathForResource("MusicaBg", ofType: "wav")!
let url = NSURL(fileURLWithPath: resourcePath)
try musicPlayer = AVAudioPlayer(contentsOfURL: url)
// SFX for Button
let resourcePath2 = NSBundle.mainBundle().pathForResource("botaoApertado", ofType: "wav")!
let url2 = NSURL(fileURLWithPath: resourcePath2)
try botaoApertado = AVAudioPlayer(contentsOfURL: url2)
} catch let err as NSError {
print(err.debugDescription)
}
What's the best way to do that?