You are probably getting lag because you are not pre-loading your sound files and therefore get a delay / delay when creating / playing. The best practice is to preload your audio files at application startup so that they are ready for immediate playback.
So, for AVPlayers, just set them to run applications, not just before playing them. Then, when you want to play music, you simply play AVPlayer.
myAVPlayer1.play()
As for SKAction.play ... its the same problem. You will need to create a link to your action, rather than calling it directly.
So in your game Scene above DidMoveToView you create your sound properties
class GameScene: SKScene { let sound1 = SKAction.playSoundFileNamed("Test", waitForCompletion: false) .... }
and than in your game in the right place, you run it
runAction(sound1)
Thus, there should be no delay because the sound is already preloaded.
Hope this helps
source share