开发者

Loop background music? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.

Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.

开发者_Python百科

Closed 4 years ago.

Improve this question
  1. What's the best way of playing background music for my iOS game? And how do I do this?

  2. What's the best format of having that music file in for playback?

  3. Will this this song happily play through the entire game, no interruptions when changing view?

  4. How can I loop this music?


You can use the 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];

and you can jump through by setting the currentTime:

player.currentTime = 10; //jump to 10th second
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜