简体   繁体   中英

detect an error on html5 video

I am trying to detect when there is an error on playing a video in html5.

To be more specific, My use case is when one is trying to play an HLS video in MAC (so "canPlayType" is at least "maybe") - yet for some reason the video does not play.

I have tried listening to 'error' event on the video tag. Doesn't work. In fact, the 'error' event is not even firing if I use an invalid url source! (See a demo here: http://mockup.on.aol.com/yogev/hls.html )

Could anyone please help?

Thanks!

You should add error event listener before you set the source of the video. So, if you add this after your error listener, you will get error callback:

document.getElementsByTagName('video')[0].src='https://someFalseurl.mp4';

Your current demo page is creating error listener after the error has already passed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM