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:
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