开发者

Problem firing method after AVAudioPlayer is finished playing

开发者 https://www.devze.com 2023-03-31 10:09 出处:网络
I saw some similar questions withdifferent solutions, but I want to know if there\'s a way using something similar to what I\'ve already come up with.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消