I'm trying to make a player, that gets a url from a tableview (not done yet). I started trying to make the player work, with MPMediaPlayerController.
NSString *video = [NSString stringWithFormat:@"http://www.youtube.com/watch?v=GurkREc-q4I"];
NSURL *url = [NSURL URLWithString:video];
MPMoviePlayerController *moviePlayerController = [[MPMoviePlayerController alloc]initWithContentURL:url];
[moviePlayerController.view setFrame:[self.view frame]];
[self.view addSubview:moviePlayerController];
[moviePlayerController setShouldAutoplay:YES];
[moviePlayerController prepareToPlay];
moviePlayerController.fullscreen = YES;
[moviePlayerController play];
When I try to add the moviePLayer as a subview I get this warning: Incompatible pointer types sending 'MPMoviePlayerController *' to parameter of type 'UIView *'.
Also, when I open the view, the app closes, and in console we have this:
2014-03-04 18:26:50.696 FavVideos[6181:70b] -[MPMoviePlayerController superview]: unrecognized selector sent to instance 0xa63c470 2014-03-04 18:26:50.735 FavVideos[6181:70b] * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[MPMoviePlayerController superview]: unrecognized selector sent to instance 0xa63c470'
Any ideas about what I'm doing wrong?
Thanks since now.
Edit:
Ok, I saw what I was doing to get the error and the "crash".
Here:
[self.view addSubview:moviePlayerController];
I changed to:
[self.view addSubview:moviePlayerController.view];
No more warnings or crashes. But the player is just a black screen, any ideas?
The reason it is blank is that the file will need to be a supported format. The list of suitable formats can be found in the Apple docs here Suitable Formats, i.e. MPEG, H.264 etc.
Currently you're asking the MPMoviePlayer to play a url, though this is the url to direct to a youtube page with a movie on it. The url will need to be the actual movie file.
Ways you can play this youtube video would be either to open the view up as a webview, directed to this youtube page, or read the Google documentation to play within the app using their api.
I hope this helps,
Cheers, Jim.