Objective c 声音应该在结束后重新开始

Objective c 声音应该在结束后重新开始,objective-c,ios4,audio,avaudioplayer,repeat,Objective C,Ios4,Audio,Avaudioplayer,Repeat,我有一个声音是在应用程序启动时启动的,它有30秒长。无论我在哪个viewcontroller中,当歌曲结束时,我如何重复歌曲 我的代码: -(void)playBgMusic { NSString *path = [[NSBundle mainBundle] pathForResource:@"bgmusic" ofType:@"aif"]; theAudio = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPa

我有一个声音是在应用程序启动时启动的,它有30秒长。无论我在哪个viewcontroller中,当歌曲结束时,我如何重复歌曲

我的代码:

-(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; }
试一试

查看以了解更多信息


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

谢谢,当我将它放入appDelegate时出现了一个错误,但它也在我的viewcontroller中工作
theAudio.numberOfLoops = -1