您好 我正在开发一个应用程序,在5分钟的循环播放不同的缓冲mp3。 当应用程序在前台运行或在iphone待机模式下运行时,它可以正常播放,但是当我尝试时 在后台,但它给了我这个错误:
Thu Feb 17 00:05:06 unknown mediaserverd [2303]:00:05:06.158 AudioQueue:AudioSessionSetClientPlayState(3582)中的错误-12985 2月17日星期四00:05:06未知mediaserverd [2303]:00:05:06.167 AudioQueue:来自AudioSessionSetClientPlayState的错误-12985(3582)
更多信息:当我在cicle中播放缓冲的mp3(第一个关闭corse)时,它可以很好地播放背景。我也尝试将缓冲的mp3数据保存到mp3文件然后播放,但这是同样的问题。 我搜索了这个错误,但没有找到相关信息。
提前致谢。
有(我认为)相关代码:
-(void) prepareAudio {
// Registers this class as the delegate of the audio session.
[[AVAudioSession sharedInstance] setDelegate: self];
// The AmbientSound category allows application audio to mix with Media Player
// audio. The category also indicates that application audio should stop playing
// if the Ring/Siilent switch is set to "silent" or the screen locks.
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryAmbient error: nil];
// Use this code instead to allow the app sound to continue to play when the screen is locked.
[[AVAudioSession sharedInstance] setCategory: AVAudioSessionCategoryPlayback error: nil];
UInt32 doSetProperty = 0;
AudioSessionSetProperty (kAudioSessionProperty_OverrideCategoryMixWithOthers,
sizeof (doSetProperty),
&doSetProperty
);
/*UInt32 category = kAudioSessionCategory_AmbientSound;
OSStatus result = AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(category), &category);
*/
// Activates the audio session.
NSError *activationError = nil;
[[AVAudioSession sharedInstance] setActive: YES error: &activationError];
}
- (void)finishedReceivingData:(NSData *)data {
if(data == nil) {
NSLog(@"cdata nil");
return;
}
if (player != nil) {
[player release];
player = nil;
}
player = [[AVAudioPlayer alloc] initWithData:data error: nil];
[player setVolume:0.1];
[player play];
}