ios – 循环背景音乐?

>为我的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

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...