AVAudioPlayer 播放完毕后触发方法出现问题
我看到了一些具有不同解决方案的类似问题,但我想知道是否有一种方法可以使用与我已经提出的类似的方法。
本质上,当玩家开始玩游戏时,uiview 将采用一种颜色,并在游戏结束时返回到起始颜色
- (void)playSoundWithColor {
self.image = self.pressedImage;
[audioPlayer play];
while ([audioPlayer isPlaying]) {
if (audioPlayer.currentTime == audioPlayer.duration)
self.image = self.startingImage;
}
}
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)playSoundWithColor {
self.image = self.pressedImage;
[audioPlayer play];
while ([audioPlayer isPlaying]) {
if (audioPlayer.currentTime == audioPlayer.duration)
self.image = self.startingImage;
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完成您想要做的事情的最佳方法是使您的类成为 AVAudioPlayerDelegate 并使用
该方法在播放器完成时立即调用,并且没有任何连续循环和内存问题。它将为您提供最可靠、最高效的整体性能。
The best way to do what you're trying to do is to make your class an AVAudioPlayerDelegate and to use
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.