如何在雪碧套件中循环播放音乐



我有一个 8 秒的 mp3 文件,我试图将其循环为主菜单音乐。我通过使用SKAction repeatActionForever来做到这一点,但是每次它重新开始时,循环之间都有一个小的停顿。这很烦人,因为这样听起来不像是一首长歌。我该如何解决这个问题?

编辑:

它也不能与AVAudioPlayer一起使用:(

使用 AVAudioPlayer 并将 numberOfLoops 属性设置为 -1,以便无限期地循环播放声音。

例如:

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];

最新更新