0
音頻不在後臺使用AVAudioPlayer iOS 9在前臺播放時播放。使用AVAudioPlayer在後臺播放音頻iOS 9
我已經設置所需的背景模式「應用程序播放音頻或數據流通過AirPlay的音頻/視頻」中的Info.plist
我還檢查音頻,背景能力
取使用的代碼:
@property (nonatomic, strong) AVAudioPlayer *ringtonePlayer;
NSString *ringtonePath = [[NSBundle mainBundle] pathForResource:@"incoming" ofType:@"wav"];
if ([ringtonePath length] <= 0) {
NSLog(@"Can't find incoming sound file");
return;
}
self.ringtonePlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL URLWithString:ringtonePath] error:nil];
self.ringtonePlayer.delegate = self;
self.ringtonePlayer.numberOfLoops = -1;
NSError *error = nil;
if (![[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback
error:&error]) {
NSLog(@"Unable to reroute audio: %@", [error localizedDescription]);
} else {
[[AVAudioSession sharedInstance] setActive:YES error:&error];
}
self.ringtonePlayer.volume = 1.0f;
[self.ringtonePlayer play];
請幫助,提前致謝。