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 questionWhat's the best way of playing background music for my iOS game? And how do I do this?
What's the best format of having that music file in for playback?
Will this this song happily play through the entire game, no interruptions when changing view?
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
精彩评论