0

I am using the following code to try and show a YouTube movie in my app. The Video player appears, shows the controls for a second, and then the movie player retracts. The app does not crash. Any ideas how to make this work?

MPMoviePlayerViewController *mpViewController = 
[[MPMoviePlayerViewController alloc] 
initWithContentURL:[NSURL URLWithString:@"http://www.youtube.com/watch?v=VKsVSBhSwJg"]];

[mpViewController shouldAutorotateToInterfaceOrientation:UIInterfaceOrientationLandscapeRight];

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];

[self presentMoviePlayerViewControllerAnimated:mpViewController];

[mpViewController release];
Chris
  • 5,485
  • 15
  • 68
  • 130

2 Answers2

0

The URL you point the player to must be a supported file format (e.g. H.264 encoded mp4). Youtube urls are HTML with an embedded player that loads the actual movie. Getting a playable mp4 in youtube is possible, but not that simple (this may have changed, last time I did this was about a year ago). Youtube videos have a few guards against hotlinking that make getting the actual H.264 URL tricky.

For testing the player, try setting up a web server with one of the sample files apple provides.

As for getting youtube videos, it is possible, it is tricky (some screen-scraping needed), it is a bit of a moving target.

fsaint
  • 8,759
  • 3
  • 36
  • 48
0

I don't remember where I read it, but I do remember that YouTube doesn't let you play videos in an MPMoviePlayerViewController -- you have to point the user to the YouTube app or use a UIWebView (as they detail here). I suppose you could do what Felz suggests but it would be against YouTube's policies.

Hope this helps!

donkim
  • 13,119
  • 3
  • 42
  • 47