1

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&amp"];
   MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
   if (moviePlayer)
   {
     [self.moviePlayer play];
   }

Please help me.

Thanks in advance.

Pugalmuni
  • 9,350
  • 8
  • 56
  • 97
Viral Narshana
  • 1,855
  • 2
  • 21
  • 45

2 Answers2

2

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

Community
  • 1
  • 1
Josh Brown
  • 52,385
  • 10
  • 54
  • 80
1
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];
Viral Narshana
  • 1,855
  • 2
  • 21
  • 45