检测<embed>标记无法加载video

我试图用下面的embedded标签(在iPad / iOS上)捕获错误:

<embed width="320" height="240" src="path/to/my/live/stream/playlist.m3u8" type="application/vnd.apple.mpegurl" postdomevents="true" id="movie1" /> 

我试图用以下方法来解决它:

 $("#movie1").on('onerror', function() { alert('error!') } ); 

我也尝试了onabortonstalledonendedonsuspend – 当video加载失败时都不会产生事件。

你需要做一个单独的HTTP请求来检查文件path的有效性。

 var http = new XMLHttpRequest(); http.open('HEAD', 'http://path/to/your/video', false); http.send(); if (http.status == 404) { throw new Error('Unable to load file') } else { // Generate your <embed> tag here }