Reputation: 1877
I want to play Youtube video within my application with url.I tried the following code, but it doesn't work.
NSURL *url = [NSURL URLWithString:@"http://www.youtube.com/v/pGqraZN5U0k&"];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
if (moviePlayer)
{
[self.moviePlayer play];
}
Please help me.
Thanks in advance.
Upvotes: 1
Views: 4376
Reputation: 1877
NSString *youTubeVideoHTML = @"<html><head>\
<body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:youTubeVideoHTML, youtube video link, self.webView.frame.size.width, self.webView.frame.size.height];
NSLog(@"html %@",html);
[self.webView loadHTMLString:html baseURL:nil];
Upvotes: 1
Reputation: 53073
YouTube videos can't be played directly in MPMoviePlayerController. You'll have to launch the YouTube app or create a UIWebView to show the video. See the following question:
Play youtube videos with MPMoviePlayerController
Upvotes: 2