【发布时间】:2016-08-01 03:45:47
【问题描述】:
我为我的应用程序制作了一个闹钟功能,在我设置闹钟时,我可以使用AVAudioPlayer 播放音乐曲目,它在后台模式下运行良好。但如果此时我打开 Youtube 应用并播放视频,那么 AVAudioPlayer 将不起作用。
请告诉我为什么会发生这种情况以及如何解决这个问题,如何同时玩两个游戏
这是我实现的代码:
NSURL *soundURL = [[NSBundle mainBundle] URLForResource:@"remind2"
withExtension:@"mp3"];
avSound = [[AVAudioPlayer alloc]
initWithContentsOfURL:soundURL error:nil];
[avSound setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];
[avSound prepareToPlay];
[avSound setNumberOfLoops:10];
[avSound setVolume:1.0];
[avSound play];
谢谢!
【问题讨论】:
标签: ios objective-c avaudioplayer