If statement to segue/ stop avplayer

My code is designed to stop the avplayer if it is playing and segue to the next view controller. The problem is if I hit the button without hitting the button to start the avplayer it causes a run time error. If the avplayer is not playing i need to be able to segue to the next avplayer.

                    @IBAction func stop () {

     //what to do if player is not playing. 
if player.isPlaying == true {
    player.stop()
}


}

@timswift Thanks very much for your question!

How about something like this?

@IBAction func stop () {

//what to do if player is not playing. 
if player.isPlaying == true {
    player.stop()
} else { //meaning player.isPlaying is false...
    performSegue(withIdentifier identifier: String, sender: Any?)
}

Would something like that work for you? Just wondering.

I hope that helps!

All the best!

Its not working. I don’t know why it should.

@timswift I’m sorry to hear that. What is the error message you’re getting?

This is the error very common error Thread 1: EXC_BAD_ACCESS (code=1, address=0x48).

This topic was automatically closed after 166 days. New replies are no longer allowed.