结束后声音应该再次开始
我有一个声音,该声音在应用程序启动时启动,长度为 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; }
i've got a sound which is started when the app starts, it's 30 seconds long. how can I repeat the song when it's over no matter in which viewcontroller i am?
my code:
-(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; }
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
查看 Apple 文档 了解更多信息。
audioPlayer 实例的所有者应该是 appDelegate,然后让它在用户位于应用程序中的任何位置播放。
Try
Look at Apple's Documentation for more info.
The owner of the audioPlayer instance should be the appDelegate then to let it play wherever the user is in the app.