0
votes

Here is my code

NSURL *url = [NSURL URLWithString:@"http://www.youtube.com/watch?v=2mcjR3TsK4s&feature=g-logo&context=G2e376ceFOAAAAAAAAAA"];
MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] initWithContentURL:url];
[self.view addSubview:mp.view];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(myMovieFinished:) name:MPMoviePlayerPlaybackDidFinishNotification object:mp];
[mp play]; 

So video shoul play when I starts the app but it is not playing. Can anybody see what is wrong in code? I included MediaPlayer framework and import Mediaplayer.h Thanks!

1
You can't just put a direct YouTube URL into a MPMoviePlayer. The URL you defined represents a web page, not video data. - Richard J. Ross III
@RichardJ.RossIII So how can i play YouTube URL? - Dmitriy Kalachniuk
You could use [UIApplication openURL:youtubeURL] which should launch the youtube.app that ships with your device, or you can do some fancy stuff to get a .mp4 link to the video itself. I can help you with some of that, just let me know. - Richard J. Ross III
Check out this link, if you have a server you can use t hat has PHP available. ngcoders.com/php/php-youtube-video-downloader-script - Richard J. Ross III
@RichardJ.RossIII please help me with that stuff "to get a .mp4 link to the video itself" - Dmitriy Kalachniuk

1 Answers

1
votes

You cannot play YouTube video via MPMoviePlayerController. Use UIWebView or default app with custom URL scheme for this aim

See also Play YouTube videos with MPMoviePlayerController instead of UIWebView