2013-07-26 22 views
3

嘗試這樣的:AVAudioSession setCategory錯誤

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

回答

7

您應該檢查的[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&error]的返回值,因爲它返回YES,如果它成功了,NO,如果它失敗了。

如果setCategory:error:的返回值爲NO,則只能查看error變量。

+0

是的,也是如此; +1給你 –

+0

檢查返回值給我一個真實的。音頻仍然沒有播放。 – Lagoo87

+0

您是否可以使用用於實際音頻播放的代碼編輯您的問題? – UpL1nK

0

試着改變你的代碼:

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

,看看你得到的東西更多的描述,樂於助人。

+0

localizedDescription導致錯誤。 – Lagoo87

+0

我對我的代碼進行了更改。也許它會幫助你? –

相關問題