如何获得YouTube视频宽高比 [英] How to get YouTube video aspect ratio
问题描述
我想获得YouTube视频的宽高比,以便相应地调整播放器的大小。我正在使用JavaScript编写YT播放器。
I'd like to get the aspect ratio of a YouTube video, to resize the player accordingly. I'm programming the YT player using JavaScript.
推荐答案
在Data API调用中唯一可以公开视频尺寸的地方是当您使用v3制作 videos.list(part = fileDetails,id = VIDEO_ID)时API,同时作为视频的所有者进行身份验证。它已在 video.fileDetails.videoStreams []。aspectRatio 财产。这不是特别有用,因为您需要作为视频所有者进行身份验证才能获得该信息。
The only place that exact video dimensions are exposed in a Data API call is when you make a videos.list(part=fileDetails, id=VIDEO_ID) call using the v3 API, while authenticated as the owner of the video. It's returned in the video.fileDetails.videoStreams[].aspectRatio property. This isn't particularly useful, since you need to be authenticated as the video's owner in order to get that info.
如果您只有一个网页,并且想要制作 JSONP 调用以获取有关给定视频是16:9还是4:3的提示,您可以通过类似
If you just have a webpage, and want to make a JSONP call to get a hint about whether a given video is 16:9 or 4:3, you can do that via something like
http://gdata.youtube.com/ feeds / api / videos / VIDEO_ID
?v = 2& alt = jsonc& callback = myCallback
http://gdata.youtube.com/feeds/api/videos/VIDEO_ID
?v=2&alt=jsonc&callback=myCallback
例如
http://gdata.youtube.com/feeds/api/videos/F1IVb2_FYxQ?v=2&alt=jsonc&callback=myCallback
在其响应中设置aspectRatio:widescreen
,这暗示视频为16:9(或接近16:9)。
has "aspectRatio":"widescreen"
set in its response, which is a hint that the video is 16:9 (or close to 16:9).
http://gdata.youtube.com/feeds/api/videos/u1zgFlCw8Aw?v=2&alt=jsonc&callback=myCallback
没有设置 aspectRatio
,这意味着视频是4:3(或接近4:3)。它并不总是精确的宽高比,但它足够接近绝大多数视频都有用。
does not have aspectRatio
set at all, which means that the videos is 4:3 (or close to 4:3). It's not always the exact aspect ration, but it's close enough for the vast majority of videos to be useful.
这篇关于如何获得YouTube视频宽高比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!