Objective-C: Play Youtube Video on App
ios, objective-c, uiwebview, youtube-api
Solution
you have to use embed link
use below code
NSString *videoURL = @"http://www.youtube.com/embed/Wq_CtkKrt1o";
instead of
NSString *videoURL = @"http://youtu.be/Wq_CtkKrt1o";
try this your problem will solve
Problem
I am trying to explore what else can i do in iOS app development and it just now that i've tried to include a video on my app. I have this code below that aims to play a youtube video when the view loads, but all i got is just a black webView. ``` NSString *videoURL = @"http://youtu.be/Wq_CtkKrt1o"; videoView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)]; videoView.backgroundColor = [UIColor clearColor]; videoView.opaque = NO; videoView.delegate = self; [self.view addSubview:videoView]; NSString *videoHTML = [NSString stringWithFormat:@"\ <html>\ <head>\ <style type=\"text/css\">\ iframe {position:absolute; top:50%%; margin-top:-130px;}\ body {background-color:#000; margin:0;}\ </style>\ </head>\ <body>\ <iframe width=\"100%%\" height=\"240px\" src=\"%@\" frameborder=\"0\" allowfullscreen></iframe>\ </body>\ </html>", videoURL]; [videoView loadHTMLString:videoHTML baseURL:nil]; ```