2015-01-21 96 views
0

取消錯誤在我的iOS SpriteKit的應用程序,我玩用AVAudioPlayer配音一定數額的秒後用戶操作後,像這樣:IOS:雖然performrequest

[self.vOSoundManager performSelector:@selector(playVoiceOverWithName:) withObject:@"Voiceover_waarhondenbrokken3" afterDelay:8.0]; 
[self.vOSoundManager setRequestBeingPerformed:TRUE]; 

當用戶執行其他操作,聲音應該停止播放。我這樣做,像這樣:

if(self.vOSoundManager.requestBeingPerformed){ 
      [NSObject cancelPreviousPerformRequestsWithTarget:self.vOSoundManager]; 
      [self.vOSoundManager stopCurrentSound]; 
     } 

的stopCurrentSound方法VoiceOverSoundManager:

- (void)stopCurrentSound{ 
self.playing = FALSE; 
[self.voiceOverPlayer stop]; 
self.voiceOverPlayer = nil; 
} 

當cancelPreviousPerformRequestsWithTarget方法被調用時,我收到以下錯誤:

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[VoiceOverSoundManager name]: unrecognized selector sent to instance 0x155a9590' 

我不知道爲什麼。有沒有人有辦法解決嗎?

+0

在你的代碼或self.voiceOverPlayer中是否還有其他AVAudioPlayer實例嗎?你是否使用唯一一個播放所有聲音的播放器? – Whirlwind 2015-01-21 13:06:33

+0

我使用VoiceOverSoundManager的其他實例(使用AVAudioPlayer),但我實現了它們來嘗試解決此問題。所以在實施之前,問題也在那裏。 – Cas 2015-01-21 13:10:36

回答

0

如果您正在使用播放器的一個實例在你的遊戲玩所有的聲音,這可能是一個問題,在執行stopCurrentSound方法後,如果沒有重新創建它:

self.voiceOverPlayer = nil; 

嘗試刪除這一行或創建一個新的播放器實例。

+0

我從VoiceOverSoundManager中刪除了該行,但仍然會引發錯誤。 – Cas 2015-01-21 13:36:04

+0

另外,我在我的VoiceOverSoundManager中有這一行: self.voiceOverPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:self.voiceOverURL error:&error]; 如果我打開斷點,它總是停在那裏,即使我自己沒有在那裏放置斷點。 – Cas 2015-01-21 13:45:49