试试这个:
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
if (error) {
NSLog(@"Error setting category: %@", [error description]);
}
将错误返回“错误设置类别:UIView”,但不确定如何解决此问题。不完全确定它在告诉我什么。
请帮忙!
编辑
音频播放:
NSURL *audioFileURL = [[NSBundle mainBundle] URLForResource:@"DemoSong" withExtension:@"m4a"];
NSError *error;
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:audioFileURL error:&error];
if (error) {
NSLog(@"%@", [error localizedDescription]);
}
[_audioPlayer setNumberOfLoops:-1];
[_audioPlayer setMeteringEnabled:YES];
[_visualizer setAudioPlayer:_audioPlayer];
[_audioPlayer prepareToPlay];
[_audioPlayer play];
NSLog(@"play audio");