本文介绍了检测<嵌入>标签无法加载视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图通过以下嵌入标记(在iPad / iOS上)捕获错误:
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!') } );
我也试过 onabort
,已安装
, onended
和 onsuspend
- 所有未生成事件时视频无法加载。
I also tried with onabort
, onstalled
, onended
, and onsuspend
- all not generating an event when the video fails to load.
推荐答案
您需要单独发出HTTP请求以检查文件路径的有效性。
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
}
这篇关于检测<嵌入>标签无法加载视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!