I had the same problem and I solved it by put "var audioPlayer: AVAudioPlayer?" in the class itself not inside any method.
When I had that error, I put the declaration in the viewDidLoad so the audio did not play and I got that error.
Topic:
Programming Languages
SubTopic:
Swift
Tags: