Detect <embed> tag failing to load video

耗尽温柔 提交于 2019-12-19 04:37:54

问题


I am trying to catch an error with the following embed tag (on iPad/iOS):

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

I tried to catch it with the following:

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

I also tried with onabort, onstalled, onended, and onsuspend - all not generating an event when the video fails to load.


回答1:


You'll need to make a separate HTTP request to check the validity of the file 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
}


来源:https://stackoverflow.com/questions/9490529/detect-embed-tag-failing-to-load-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!