1

I have tried to play audio in my Sprite Kit game with the line:

self.run(SKAction.playSoundFileNamed("DingSoundEffect.wav", waitForCompletion: false))

However nothing seems to happen. I looked at another swift2 solution as well but it did not seem to work either.

var sound = SKAction.playSoundFileNamed("sound.mp3", waitForCompletion: false)

override func didMoveToView(view: SKView) {
playSound(sound)
//call playSound method when you want
}

func playSound(sound : SKAction)
{
runAction(sound)
}

My app does not crash, however I can not hear a sound being played. Can I use this method to play audio in Swift 3 or do I have to use the AVAudioPlayer. Thanks in advance.

joshLor
  • 1,034
  • 1
  • 12
  • 27
  • Are you trying to play the sound when you touch a button? – sicvayne Mar 29 '17 at 02:18
  • Your code works for me so you most likely misspelled your sound name. You have to make sure the name in the SKAction is spelled exactly like the sound file name in your project. You should also stick with the second option in your question, which preloads your song and will avoid lag when playing it the first time. – crashoverride777 Apr 06 '17 at 13:19
  • I already fixed it, it was a dumb problem my ringer was just off. – joshLor Apr 06 '17 at 15:02

0 Answers0