IOS >> Embed YouTube Video Using UIWebView - Video Does Not Play

I am trying to play a YouTube video in my application. It seems I get to the right place, but the video does not play. I run the application on the device itself (not on the simulator).

this is the code i use:

- (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 loads, but when I press the PLAY button, I get "This video is currently unavailable":

enter image description here

I tested the ID of the embedded video (copy and paste into the web page) and it will find the corresponding video (for example, I assume that I have the correct video ID).

Does anyone know what I'm doing wrong?

+4
source share
2 answers

I had the same problem, and that was because I used the user agent in my web browser, so youtube didn't show the proper video.

+1
source

Your problem is that you are using:

 http://www.youtube.com/embed/VIDEO_ID&feature?autoplay=1 

Must be:

 http://www.youtube.com/embed/VIDEO_ID?feature&autoplay=1 

This is due to the fact that the URL itself is http://www.youtube.com/embed/VIDEO_ID , and the parameters are a function and autoplay = 1.

Cheers Morten

0
source

Source: https://habr.com/ru/post/1486793/


All Articles