Please find the necessary solution here:
Record browser tab switch
All you have to change is replace the line
SoSciTools.attachEvent(window, "blur", countBlur);
by this one:
document.getElementById("player").addEventListener("play", countBlur);
then remove everything as of audio.onplay
in your code and place the "new" code from the manual there instead.
Oh, and please forget about the <?php
. You cannot use PHP code within JavaScript code, and even if you could, it would not work, because PHP runs on the server (between the pages) while JavaScript runs in the browser (on the pages).