SemAllush
SemAllush

Reputation: 479

How do I loop music in Sprite Kit?

I have an 8 second mp3 file and I'm trying to loop it as main menu music. I do this by using SKAction repeatActionForever, however every time it starts over there is a small pause between the loops. This is very annoying since it doesn't sound like it is one long song this way. How can I fix this?

EDIT:

It also doesn't work with AVAudioPlayer :(

Upvotes: 0

Views: 190

Answers (1)

sangony
sangony

Reputation: 11696

Use AVAudioPlayer and set the numberOfLoops property to -1 in order to loop the sound indefinitely.

For example:

NSError *error;
NSURL *soundURL = [[NSBundle mainBundle] URLForResource:@"SomeSound.wav" withExtension:nil];
myPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:soundURL error:&error];
myPlayer.numberOfLoops = -1;
myPlayer.volume = 0.4;
myPlayer.delegate = self;
[myPlayer prepareToPlay];
[myPlayer play];

Upvotes: 1

Related Questions