Problem firing method after AVAudioPlayer is finished playing
I saw some similar questions with different solutions, but I want to know if there's a way using something similar to what I've already come up with.
Essentially, a uiview will take one color when the player starts playing, and go back to the starting color when it is finished playing
- (void)playSoundWit开发者_运维百科hColor {
self.image = self.pressedImage;
[audioPlayer play];
while ([audioPlayer isPlaying]) {
if (audioPlayer.currentTime == audioPlayer.duration)
self.image = self.startingImage;
}
}
The best way to do what you're trying to do is to make your class an AVAudioPlayerDelegate and to use
audioPlayerDidFinishPlaying:successfully:
That method is called right when the player finishes and doesn't have any continuous loop and memory issues. It will give you the most reliable and efficient performance overall.
加载中,请稍侯......
精彩评论