iOS 8 Swift Audio Playback Execute Method On Compl

2019-02-24 11:21发布

问题:

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



标签: swift ios8