问题
iPhone App :How to play Youtube video in app using MPMoviePlayerController
for that i write the code:
NSString *urlAddress = @"http://www.youtube.com/xyz";
NSLog(@"URL ADDress : %@",urlAddress);
//Create a URL object.
NSURL *url = [NSURL URLWithString:urlAddress];
movie = [[MPMoviePlayerController alloc] initWithContentURL:url];
movie.scalingMode=MPMovieScalingModeAspectFill;
movie.view.frame = CGRectMake(0.0, 0.0, 320.0, 460.0);
[self.view addSubview:movie.view];
[movie play];
if i pass the url of local directory it is playing video
NSString* filePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Video.mp4"];
NSURL* url = [[[NSURL alloc] initFileURLWithPath:filePath] autorelease];
How can I play video directly from youtube url to MPMoviePlayerController?
回答1:
There is a great thread that on IphoneDevSDk.
They work with a hidden UIWebView: http://www.iphonedevsdk.com/forum/iphone-sdk-development/61447-how-play-youtube-movie.html
回答2:
NSString *url = @"http://www.example.com/path/to/movie.mp4";
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
[moviePlayer play];
Check this and release the controller.
来源:https://stackoverflow.com/questions/6029859/iphone-app-how-to-play-youtube-video-in-app-using-mpmovieplayercontroller