iPhone App :How to play Youtube video in app using MPMoviePlayerController

戏子无情 提交于 2020-01-22 12:58:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!