Reputation: 5711
I'm trying to play a YouTube video in my app. It seems like I get to right place, but the video is not playing. I'm running the app on an actual device (not on the simulator).
this is the code I'm using:
- (void)viewDidLoad
{
[super viewDidLoad];
NSString *htmlString = @"<html><head>\
<meta name = \"viewport\" content = \"initial-scale = 1.0, user-scalable = no, width = 320\"/></head>\
<body style=\"background:#000;margin-top:0px;margin-left:0px\">\
<iframe id=\"ytplayer\" type=\"text/html\" width=\"320\" height=\"240\"\
src=\"http://www.youtube.com/embed/VIDEO_ID&feature?autoplay=1\"\
frameborder=\"0\"/>\
</body></html>";
//VIDEO_ID holds the video embedded code I get from YouTube
[self.webView loadHTMLString:htmlString baseURL:[NSURL URLWithString:@"http://www.youtube.com"]];
}
The YouTube player is loading, but when I click on the PLAY button I get "This video is currently unavailable":
I tested the embedded video id (copy&paste into a web page) and it finds the related video (i.e. I assume I have the correct video id).
Anyone has any idea what am I doing wrong?
Upvotes: 4
Views: 3094
Reputation: 1361
Your problem is the url you are using:
http://www.youtube.com/embed/VIDEO_ID&feature?autoplay=1
Should be:
http://www.youtube.com/embed/VIDEO_ID?feature&autoplay=1
This is because the url itself is http://www.youtube.com/embed/VIDEO_ID
and the parameters are feature and autoplay=1.
Cheers Morten
Upvotes: 0
Reputation: 53
I had the same issue and it was because I was using a custom user agent in my webview so youtube wasn't serving the proper video.
Upvotes: 1