Reputation: 1365
Using the youtube javascript api (http://code.google.com/apis/youtube/js_api_reference.html), I am trying to allow a user to embed a video into some content he creates in my app. I have gotten everything working, except for being able to detect and handle the case that embedding is not allowed for the video.
Currently, the player loads and shows a thumbnail of the disallowed video, and it only gives an error once the user tries to play it. This is bad because the user may not play the video before saving / sending his content. I would like to preemptively detect that the video is not allowed to be embedded, and display a helpful message to the user.
The only solution I can see is to actually play it (programmatically) and handle the error that is raised at that point.
Existing workaround:
Is there a better way?
Thanks!
-Rob
Upvotes: 4
Views: 4252
Reputation: 4098
I think that you might be looking for the videoSyndicated
or the videoEmbeddable
parameter. The API documentation says:
The videoEmbeddable parameter lets you to restrict a search to only videos that can be embedded into a webpage. If you specify a value for this parameter, you must also set the type parameter's value to video.
Reference: https://developers.google.com/youtube/v3/docs/search/list#videoEmbeddable
The videoSyndicated parameter lets you to restrict a search to only videos that can be played outside youtube.com. If you specify a value for this parameter, you must also set the type parameter's value to video.
Reference: https://developers.google.com/youtube/v3/docs/search/list#videoSyndicated
With both:
GET https://www.googleapis.com/youtube/v3/search?&part=snippet,statistics&videoSyndicated=true&videoEmbeddable=true&key=${yourKey}
Upvotes: 1
Reputation: 12985
I know this isn't directly to the question, but in case someone using PHP stumbles upon this problem, there's a method getNoEmbed()
in a Zend_Gdata_YouTube_VideoEntry
.
Taken from the docs:
If the return value is an instance of
Zend_Gdata_YouTube_Extension_NoEmbed
, this video cannot be embedded.
Upvotes: 0
Reputation: 161
You can grab the JSON feed for that video entry before you embed it and see if "yt$format":5 exists, which is the embed SWF. It won't be there if embedding is disabled.
http://gdata.youtube.com/feeds/api/videos/video_id?v=2&alt=json-in-script
Upvotes: 6