objective-c - 结束后声音应重新开始

标签 objective-c ios4 audio avaudioplayer repeat

我有声音,该声音在应用程序启动时启动,它的长度为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/

相关文章:

ios - SVG/iOS - 如何使用 SVGKit?

android - 在Android上切换USB音频

python - 如何在python 3中更改或禁用tkinter消息框的默认声音

ios - 我想在 iOS 中单击按钮时更改我自己的应用程序语言

objective-c - 查询 UITableView 选定的单元格以显示 "Delete"按钮

php - 表的 FMDB 结果到 JSON 对象,遵循列的顺序。

iphone - NSXMLParser 和 XML 类型 ="html"HTML 编码

objective-c - 如何在 Objective-C/iOS 中创建准确的计时器事件?

iphone - 关闭动画不会运行

javascript - jquery - 使用 $(document).on ('play' 、 'video' 、 function(){}) 时播放不起作用