0

I'm having trouble with the function audioPlayerDidFinish playing. I have added the AVAudioPlayerDelegate to my view controller class and defined the function. When I call the function I get the error "Cannot convert value of type 'AVAudioPlayer.Type' to expected argument type" What am I doing wrong? Let me know if I need to add more code for you to see.

    func buttonPressed() {
    if currentSound == sound {
        currentSound = "None"
        activateBlankCircle()
        audioPlayer.stop()
    }
    else {
        currentSound = sound
        audioPlayer.prepareToPlay()
        activateRedCircle()
        playSound()
        audioPlayerDidFinishPlaying(AVAudioPlayer, successfully: Bool)
        //Cannot convert value of type 'AVAudioPlayer.Type' to expected argument type

    }

}
Talon Brown
  • 127
  • 13
  • If you explain more about what you are trying to do and why are you implementing `audioPlayerDidFinishPlaying`, answers will probably be more helpful. – Sweeper Jan 11 '18 at 07:22

1 Answers1

0

Delegate methods should not be called by the delegate itself.

audioPlayerDidFinishPlaying here is a delegate method. You are supposed to implement it (which you have) and set self as the audio player's delegate. The method will be called by the AVAudioPlayer at an appropriate time i.e. when it finishes playing a sound.

So you should remove the call to audioPlayerDidFinishPlaying and everything should work fine. From the looks for it, you are implementing a start/stop playing button. If you want to do something when the player finishes playing, you can set self as the audioPlayer.delegate in viewDidLoad. And the method will be called when it finishes playing a sound.

Sweeper
  • 213,210
  • 22
  • 193
  • 313
  • It worked!!! Thank you so much!! How do I mark this question as answered and give you credit for answering it? :D – Talon Brown Jan 11 '18 at 07:32