声音应该在结束时重新开始

时间:2011-04-06 18:20:04

标签: objective-c ios4 audio avaudioplayer repeat

我有一个声音是在应用程序启动时启动的,它长达30秒。无论我在哪个视图控制器中,怎么能在它结束时重复这首歌呢?

我的代码:

-(void)playBgMusic {

NSString *path = [[NSBundle mainBundle] pathForResource:@"bgmusic" ofType:@"aif"];
theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:path] error:NULL];
theAudio.delegate = self;
[theAudio play];    }


-(id)initWithCoder:(NSCoder *)coder {

self = [super initWithCoder:coder];

if(self)
{
    [self playBgMusic];
}

return self; }

1 个答案:

答案 0 :(得分:2)

尝试

theAudio.numberOfLoops = -1

请查看Apple's Documentation以获取更多信息。

audioPlayer实例的所有者应该是appDelegate,然后让用户在应用中的任何位置播放。

相关问题