我有声音,该声音在应用程序启动时启动,它的长度为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; }
最佳答案
尝试
theAudio.numberOfLoops = -1
查看Apple's Documentation了解更多信息。
audioPlayer实例的所有者应该是appDelegate,然后使其可以在用户位于应用程序中的任何位置播放。
关于objective-c - 结束后声音应重新开始,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5571122/