I am playing an audio file in Swift for iOS 8. I need to be able to know when the sound is finished. How can I have a method executed when the sound is finished?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
It depends on how you're playing it. Look for a delegate method, a notification, or an observable property whose state change can trigger a KVO notification.
For example, if you're using an AVAudioPlayer, its delegate
gets notified by a delegate method, which you can find out about here: https://developer.apple.com/library/ios/documentation/avfoundation/reference/AVAudioPlayerDelegateProtocolReference/index.html#//apple_ref/doc/uid/TP40008068