问题描述
我正在使用Swift for iOS 8播放音频文件。我需要能够知道声音何时结束。如何在声音结束时执行方法?
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?
推荐答案
这取决于你如何演奏它。查找委托方法,通知或可观察属性,其状态更改可以触发KVO通知。
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.
例如,如果您正在使用AVAudioPlayer,则其 delegate
通过委托方法获得通知,您可以在此处找到:
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
这篇关于完成时iOS 8 Swift音频播放执行方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!