OGeek|极客世界-中国程序员成长平台

标题: javascript - 检测 <embed> 标签无法加载视频 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 11:55
标题: javascript - 检测 <embed> 标签无法加载视频

我正在尝试使用以下嵌入标签(在 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 - 所有这些都不会生成事件视频加载失败。



Best Answer-推荐答案


您需要发出单独的 HTTP 请求来检查文件路径的有效性。

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
}

关于javascript - 检测 <embed> 标签无法加载视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9490529/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4