[英]How can I play continuous music in the background when my iPhone app is running?
当用户积极运行我的应用程序时,我想运行轻音乐(不间断)。 当用户退出我的应用程序时,音乐将自动停止。 我尝试了以下代码来执行连续音乐播放(即循环播放音乐)。 但是它实际上并没有循环。 一旦说完音乐,音乐就会结束。
- (void) PlayLoopMusic {
NSString* path;
NSURL* url;
path = [[NSBundle mainBundle] pathForResource:@"music" ofType:@"mp3"];
url = [NSURL fileURLWithPath:path];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:NULL];
[player prepareToPlay];
[player setVolume: 0.030];
[player setDelegate: self];
// Start playing it while starting the game ...
[player play];
}
有人可以建议一些方法来实现循环播放连续音乐吗?
我还没有机会进行测试,但是您是否尝试将numberOfLoops
属性设置为负值? AVAudioPlayer API文档指示这是使声音无限循环的正确方法。
组,
player.numberOfLoops = -1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.