Closed. This question is opinion-based。它当前不接受答案。
想改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。
去年关闭。
在iOS游戏中播放背景音乐的最佳方法是什么?我该怎么做?
播放音乐文件的最佳格式是什么?
这首歌会在整个游戏中愉快地播放吗,在切换视图时不会中断吗?
如何循环播放此音乐?
您可以通过设置
想改善这个问题吗?更新问题,以便editing this post用事实和引用来回答。
去年关闭。
在iOS游戏中播放背景音乐的最佳方法是什么?我该怎么做?
播放音乐文件的最佳格式是什么?
这首歌会在整个游戏中愉快地播放吗,在切换视图时不会中断吗?
如何循环播放此音乐?
最佳答案
您可以使用AVAudioPlayer
:
NSString *soundFilePath = [[NSBundle mainBundle] pathForResource:@"mySound" ofType:@"mp3"];
NSURL *soundFileURL = [NSURL fileURLWithPath:soundFilePath];
AVAudioPlayer *player = [[AVAudioPlayer alloc] initWithContentsOfURL:soundFileURL error:nil];
player.numberOfLoops = -1; //infinite
[player play];
您可以通过设置
currentTime
来跳过:player.currentTime = 10; //jump to 10th second