Reputation: 21
class ViewController: UIViewController, AVAudioPlayerDelegate {
func audioPlayerDidFinishPlaying (_ player:AVAudioPlayer, successfully flag: Bool) {
endcheck.text = "end"
}
@IBAction func play(_ sender: Any) {
do
{
let url = Bundle.main.path (forResource: String(myIndex), ofType: "mp3")
try player = AVAudioPlayer (contentsOf: NSURL(fileURLWithPath: url!) as URL)
}
catch{
}
player.play()
let hasThePlayerEnded = audioPlayerDidFinishPlaying(_:player, successfully:true)
}
super.viewDidLoad()
self.player.delegate = self
}
Right at the moment when I click "play" button, I see "end" not when a sound has finished playing. I'm sure I did something wrong. how should I fix it?
Upvotes: 0
Views: 292
Reputation: 1391
Remove the following statement from play()
method
let hasThePlayerEnded = audioPlayerDidFinishPlaying(_:player, successfully:true)
Upvotes: 1