Set html audio play/pause based on a cookie (works only on pause, but not on play)

Hi everyone!

I’m trying to make background audio remember the play/pause state. I have achieved pausing it and storing the pause state in the cookie, so when I go between page one and two it stays paused (vs autoplaying initially on both pages), but when I click play after that and refresh the page, even though the cookie is changing to “false” in the inspector, the audio doesn’t play.

And let alone the audio, which is maybe too tricky with autoplay, the div colour doesn’t change to green although it should base on a “false” isMuted cookie.

Live demo