我希望我的应用程序音频在后台运行,并且我遵循this tutorial但它不起作用。当我按下home按钮时,我的应用程序音频仍然停止,我意识到它没有调用“applicationDidBecomeActive”或“applicationDidEnterBackground”(即使我禁用了“应用程序不在后台运行”的设置,问题仍然存在)。过去一周我一直在处理这个问题。IOS应用程序不会在后台运行
到目前为止,我已经做到了这步:
- 新增AVFoundation框架,并宣布
#import <AVFoundation/AVFoundation.h>
- 设置了音频
NSString *audioName = [NSString stringWithFormat:@"audio%d", (nimages)];
NSString *soundPath =[[NSBundle mainBundle]pathForResource:audioName ofType:@"mp3"];
NSURL *soundURL = [NSURL fileURLWithPath:soundPath];
NSError *error = nil;
AVAudioPlayer *audio = nil;
audio = [[AVAudioPlayer alloc]initWithContentsOfURL:soundURL error:&error];
audio.numberOfLoops = -1;
audio.volume = 0.9;
if (error) {
NSLog(@"%@", [error localizedDescription]);
NSLog(@"Unable to load file");
}else {
//Make sure the system follows our playback status
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
[[AVAudioSession sharedInstance] setActive: YES error: nil];
//Load the audio into memory
[audio prepareToPlay];
}
- 添加行AVAudioSession in plist
更新时间:
我的应用程序是一个音频应用程序,用户可以播放特定的配乐我的应用程序,即使它进入后台。可能吗?
我觉得我的应用程序考虑音频应用程序,因为用户可以继续在后台监听我的应用程序音频音乐。 –