2014-10-10 73 views

回答

2

這取決於你如何玩它。查找其狀態更改可觸發KVO通知的委託方法,通知或可觀察屬性。 https://developer.apple.com/library/ios/documentation/avfoundation/reference/AVAudioPlayerDelegateProtocolReference/index.html#//apple_ref/doc/uid/TP40008068

+0

委託方法就是我在尋找:

例如,如果您使用的是AVAudioPlayer,其delegate獲得由委託的方法,你可以找到關於此通知。我實現了Apple頁面上顯示的方法,但沒有被調用。這裏是我的代碼: [P] 加載聲音文件: VAR introSound = NSURL(fileURLWithPath:NSBundle.mainBundle()pathForResource( 「前奏」,ofType: 「WAV」)!) 播放聲音: audioPlayer = AVAudioPlayer(contentsOfURL:soundResource,錯誤:&錯誤) audioPlayer.prepareToPlay() audioPlayer.play() 委託方法: FUNC audioPlayerDidFinishPlaying(播放器:AVAudioPlayer! 成功標誌:布爾){ 的println( 「已完成」 ) } – 2014-10-10 18:14:29

+0

它不會被調用,因爲你不是'delegate'。如果您想要發送委託方法,您必須成爲委託人。 – matt 2014-10-10 18:39:03

+0

下面是一些工作示例代碼:https://github.com/mattneub/Programming-iOS-Book-Examples/blob/master/bk2ch14p643ducking/ch27p912ducking/Player.swift – matt 2014-10-10 18:41:55