我有一个运行视频幻灯片的 iframe 元素。
我需要检查视频是否能够播放。如果不是我必须显示验证消息。
我确实用这个
`$.getJSON('https://noembed.com/embed',
{ format: 'json', url: someURL }, function (data) {
if (data.error) {
self._validationMessage.show(); //show the valiadtion message from html
}
});`
但问题是某些视频包含错误,这些错误不会阻止视频在其他地方运行。
我也尝试选择 iframe 元素的正文,因为当视频无法运行时,页面为空白,因此正文为空,但无法选择它。
我不能使用 youtube API,因为它需要个人 API key 。
这些是每个错误的 Json 文件
第一个 - 预期 data.error 返回错误:“401 Unauthorized ↵”
{"error":"401 Unauthorized \n","url":"http://www.youtube.com/watch?v=_pfSezsmsuw"}
第二个不包含任何错误,但 data.error 返回错误:“找不到匹配的提供者 ↵”
{"thumbnail_url":"https://i.ytimg.com/vi/LhqLn1wKJAw/hqdefault.jpg","width":480,"height":270,"provider_url":"https://www.youtube.com/","author_name":"Largest Dams","title":"The Largest Aircraft Carrier in The World (full video)","version":"1.0","thumbnail_height":360,"type":"video","thumbnail_width":480,"provider_name":"YouTube","author_url":"https://www.youtube.com/user/itsd3000","url":"http://www.youtube.com/watch?v=LhqLn1wKJAw","html":"\n<iframe width=\" 480\" height=\"270\" src=\"https://www.youtube.com/embed/LhqLn1wKJAw?feature=oembed\" frameborder=\"0\" allowfullscreen=\"allowfullscreen\"></iframe>\n"}
最佳答案
当我厌倦了仅使用链接观看 YouTube 视频时,它说视频不可用。认为这是问题所在。尝试使用另一个 YouTube 视频,看看是否可行。
关于javascript - 检查视频是否能够在 iframe 中播放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42811906/