I’d like to log when users listen to an audio element for more than 5 seconds. How can I detect this with HTML5?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I would handle the play event, and then use a setTimeout call track when they’re done. Something like this (pseudo code):
As always, this could get far more complex depending upon your needs. You could also just use the ontimeupdate event to track where the playhead is currently sitting. For a reference on html5 audio events, check out this page:
https://developer.mozilla.org/en/DOM/Media_events
Good luck!