2015-01-02 55 views
4

我有一個簡單的代碼來播放聲音通過AVAudioPlayerAVAusioSession PTY錯誤模擬器

NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] 
             pathForResource:@"beep" 
             ofType:@"mp3"]]; 

self.player = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:nil]; 
self.player.volume = 1; 
[self.player prepareToPlay]; 

我的異常斷點會停在prepareToPlay和控制檯日誌中寫道:

ERROR: AVAudioSessionUtilities.h:111: GetProperty: AudioSessionGetProperty ('prp?') failed with error: 'pty?

2倍攻傳後通過這個斷點,應用程序不會崩潰。這隻發生在模擬器中。 有什麼建議嗎?

回答

1

以下代碼可能會對您有所幫助。

NSURL *url; 
url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/beep.mp3", [[NSBundle mainBundle] resourcePath]]]; 
self.audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error]; 
self.audioPlayer .delegate = self; 
[self.audioPlayer prepareToPlay]; 
[self.audioPlayer play];