【问题标题】:Detect <embed> tag failing to load video检测 <embed> 标签无法加载视频
【发布时间】:2012-03-18 10:21:46
【问题描述】:

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

【问题讨论】:

  • 我很确定您不能将此参数与 .on() 一起使用,而是使用原始写作 $("#movie1")[0].onerror = ...
  • @Oddant:这似乎也不起作用。
  • 你试过$("#movie1").error(...) 吗?
  • 找到运气了吗?我也在尝试。

标签: javascript jquery ios video-streaming embed


【解决方案1】:

您需要发出单独的 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
}

【讨论】:

    猜你喜欢
    • 2021-04-09
    • 1970-01-01
    • 1970-01-01
    • 2020-05-07
    • 1970-01-01
    • 1970-01-01
    • 2014-01-08
    • 2011-11-19
    • 1970-01-01
    相关资源
    最近更新 更多