Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVAudioSession setCategory error

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");
like image 275
Lagoo87 Avatar asked Mar 24 '23 00:03

Lagoo87


1 Answers

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.

like image 194
UpL1nK Avatar answered Apr 01 '23 08:04

UpL1nK