在尝试加载YouTube视频之前,如何判断该视频是否可嵌入? [英] How can I tell if a YouTube video is embeddable before I try and load it?

查看:169
本文介绍了在尝试加载YouTube视频之前,如何判断该视频是否可嵌入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个无色YouTube播放器,我正在尝试将视频加载到其中,但是只有部分视频可以工作-并非全部。如果我没记错的话,那些没有加载的视频是由于侵犯版权而引起的(例如,没有加载动画片的某些情节,但是有孩子在做后空翻的家庭电影)。我正在尝试做的是找出这些视频是否可以加载,无论是在我们尝试加载之后还是之前。

I've got a chromless YouTube player that I'm trying to load videos into, but only some videos work--not all. If I'm not mistaken, the ones that aren't loading are due to copyright infringement (e.g., some episode of a cartoon doesn't load, but a home movie of a kid doing a backflip does). What I'm trying to do is either find out whether or not these videos can load, either after we try to load them or before.

例如,这里是Nataly Dawn的两个视频

As an example, here are two videos by Nataly Dawn. One loads, the other doesn't.

// loads and plays the video
ytplayer.loadVideoById("GhDGdT33K0k");

// doesn't load/play the video
ytplayer.loadVideoById("-KYUPJIzCyM");

通过查看两个工作视频无效的视频,我似乎看不到任何表明该视频不可嵌入的内容。 [我正在寻找< yt:accessControl> 标记或缺少的 yt:format ='5'( cf. 如何使用Youtube API来检查视频是否可嵌入? ),但无济于事。]

From looking at the data of both the working video and the non-working video, I can't seem to see anything that would indicate that the latter is non-embeddable. [I'm looking for <yt:accessControl> tags or a missing yt:format='5' (cf. How do I use the Youtube API to check if a video is embeddable?), but to no avail.]

在控制台中尝试过, loadVideoById 始终返回 undefined ,无论是否视频实际加载。我似乎找不到API方法来确定视频是否这样做。

From what I've tried in the console, loadVideoById always returns undefined, regardless of whether or not the video actually loads. I can't seem to find an API method to determine whether or not the video has done so.

推荐答案

您提到的两个视频对我来说似乎是可以加载和播放的。例如,使用: Google代码游乐场,然后将视频插入选项标签

Both videos you mentioned appear to be loadable and playable for me. For example use: the google code playground and insert your videos into the option tags of the HTML.

不过,这里有一些提示。

Here's a few tips though.

  • Use the "v=2" parameter in your gdata request to use the current YT data API.
  • This blog post lists several additional restrictions that you may need to check for to determine if a video playable or embeddable.
  • Some videos can be embedded, but don't play. In that case the only thing you can do is to use the JavaScript PlayerAPI to look for a stateChange event that says that it's playing, and then use a setInterval to poll the video through getCurrentTime to find out if it is actually playing. This is a little crazy for most applications though.

这篇关于在尝试加载YouTube视频之前,如何判断该视频是否可嵌入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆