Reputation: 504
I am trying to have my client application filter out videos that do not allow embedding. My understanding here is that there is no way to limit the feed (i.e. format=5 is insufficient) to do this and that I must check the properties of the entry myself, for the <yt:accessControl>
tag and the <app:control>
and <yt:state>
tags.
This isn't working for me.
For example, this video: https://www.youtube.com/watch?v=waxat-_tRH8
doesn't embed: https://www.youtube.com/embed/waxat-_tRH8
even though the API returned data indicates (as far as I can tell) that it should be able to embed: https://gdata.youtube.com/feeds/api/videos/waxat-_tRH8?v=2
The entry does not contain any <yt:noembed>
tag (see prior question) and the <media:restriction type='country' relationship='deny'>ME DE RS</media:restriction>
does not explain this since I am in the US (see prior question) (see prior question).
What am I missing here?
EDIT: The embed link above works in my web browser, but not in my client app's WebView....!?
Upvotes: 12
Views: 49275
Reputation: 705
Add player vars while initializing youtube sdk:
NSDictionary *playerVars = @{
@"origin" : @"http://www.youtube.com",
};
[self.playerView loadWithVideoId:@"videoid" playerVars:playerVars];
Enjoy!
Upvotes: 0
Reputation: 461
For those who experience the same issue in webView on Android. I fixed that by adding the referer header field similarly to what @RainCast did in her answer.
Map<String, String> extraHeaders = new HashMap<>();
extraHeaders.put("Referer", "http://youtube.com");
String url = "https://www.youtube.com/embed/dQw4w9WgXcQ";
webView.loadUrl(url, extraHeaders);
It works for pure URL, but I don't know how to pass those parameters while injecting iFrame in the webView.
Upvotes: 1
Reputation: 11333
You can use this answer. This worked perfectly in my case-
Adding origin
in player vars
as https://www.youtube.com
Upvotes: 3
Reputation: 11
try like this instead
<iframe width="300" height="200" src="www.youtube.com/embed/<video-id>?enablejsapi=1" frameborder="0" allowfullscreen></iframe>
Upvotes: -1
Reputation: 1000
As Jeff Posnick pointed out, some videos have blacklists. If you try and request a video with a blacklist from an app and not a web page, you will see this error message:
"This video contains content from ___. It is restricted from playback on certain sites."
It's likely your app is NOT blacklisted, and that you're being blacklisted incorrectly. To fix this, you need to supply your Youtube API request with an origin (as atulkhatri pointed out).
In your request header for the Youtube video, set Referer
to the domain in which you intend to be making the call from, (for ex. the domain of your app's corresponding website). If you don't have a domain, you could easily write some other domain, and that might work too.
For Android (Java), you can see an example here.
For iOS, look above
For React Native, you can use the origin
prop on the component to your domain (origin
is mentioned in the docs but doesn't tell you much about it).
Here is another example of the same issue in a browser when an extension blocked the Referer
header from being sent for good measure.
This answer works for the V3 API of Youtube.
Upvotes: 9
Reputation: 4491
Actually, if you embed your video here:
http://www.w3schools.com/html/tryit.asp?filename=tryhtml_default
Like this:
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
</head>
<body>
<iframe width="420" height="315" src="https://www.youtube.com/embed/waxat-_tRH8" frameborder="0" allowfullscreen></iframe>
</body>
</html>
It actually is playable. So the problem actually comes back to why it works on website but not iOS mobile app?
Then I found out about this post:
http://support.metacdn.com/hc/en-us/articles/204513985-Video-Player-Embed-Restriction
It explains that the embed could be restricted due to lack of HTTP header "Referer" field.
So after setting the refer field, this video will be playing in iOS app:
let youtubeURL = NSURL(string: "https://www.youtube.com/embed/YQHsXMglC9A?autoplay=1")
let youtubeRequest = NSMutableURLRequest(URL: youtubeURL!)
youtubeRequest.setValue("https://www.youtube.com", forHTTPHeaderField: "Referer")
webView.loadRequest(youtubeRequest)
Wala, it works now!
Are you happy? cause I am happy. :)
Upvotes: 6
Reputation: 56044
Certain videos have a domain-level whitelist or blacklist applied to them. This is done at the discretion of the content owner.
If there is a whitelist or a blacklist, and the domain of the embedding site can't be determined (perhaps because of there not being a real referring domain in the case of your native application), then the default behavior is to block playback.
This blog post has a bit more detail as well: http://youtube-eng.blogspot.co.uk/2011/12/understanding-playback-restrictions_28.html
Upvotes: 9