播放音频,而在后台模式行不通
问题描述:
在我的应用程序的音频没有被当我把我在后台模式下的应用程序..我在这个网站看到过这样的问题itself.it提到扮演的是播放音频,而在后台模式行不通
1)应用-的info.plist添加到背景模式在我添加了音频会议
if([player isPlaying])
{
[player stop];
}
NSError *error=nil;
int trackid=arc4random()%10+1;
NSString *trackname=[NSString stringWithFormat:@"trk-%d",trackid];
NSLog(@"%@",trackname);
NSString *newAudioFile = [[NSBundle mainBundle] pathForResource:trackname ofType:@"mp3"];
player = [[AVAudioPlayer alloc] initWithContentsOfURL:[NSURL fileURLWithPath:newAudioFile] error:NULL];
AVAudioSession *audioSession = [AVAudioSession sharedInstance];
NSError *setCategoryError = nil;
[audioSession setCategory:AVAudioSessionCategoryPlayback error:&setCategoryError];
if (setCategoryError) { /* handle the error condition */ }
NSError *activationError = nil;
[audioSession setActive:YES error:&activationError];
if (activationError) { /* handle the error condition */ }
if(error) {
NSLog(@"%@",&error);
}
[player prepareToPlay];
[player play];
player.numberOfLoops=1;
,但仍当我把应用研究背景mode.it恢复时,它是不工作的支持代码“音频” 2)我把应用程序放回去了。我错过了什么?
答
使用该线路 - (无效)viewDidLoad中
[UIApplication sharedApplication].idleTimerDisabled = YES;
+0
我试过这也同样,音频停止播放,而在后台模式 – sujith1406
+0
不使用AVAudioSession - 使用AudioToolbox和 #import
当你把应用程序在其下研究背景模式存在,你必须加入“ADD播放音频”项0。你有没有添加这个? –
亚,我已经提到(在应用程序info.plist礼仪??) – sujith1406