AVAudioSession setCategory error

天涯浪子 提交于 2020-01-24 06:07:05

问题


Trying this:

[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];

if (error) {
    NSLog(@"Error setting category: %@", [error description]);
}

Getting the error back "Error setting category: UIView" but am not sure how to go about fixing this. Not entirely sure what it's telling me.

Help please!

EDIT

Audio Playback:

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");

回答1:


You should check the return value of [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error], as it returns YES if it succeeded and NO if it failed.

Only look at the error variable if the return value of setCategory:error: is NO.




回答2:


Try changing your code to:

NSError * error = nil;
BOOL success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error];
if(NO == success)
{
    NSLog(@"Error setting category: %@", [error localizedDescription])
}

and see if you get something more descriptive and helpful.



来源:https://stackoverflow.com/questions/17889789/avaudiosession-setcategory-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!