iPhone应用程序:如何使用MPMoviePlayerController在应用程序中播放Youtube视频
为此我写了代码:
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];
如果我传递本地目录的网址,则正在播放视频
NSString* filePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingPathComponent:@"Video.mp4"];
NSURL* url = [[[NSURL alloc] initFileURLWithPath:filePath] autorelease];
如何直接从youtube网址播放视频到MPMoviePlayerController?
答案 0 :(得分:2)
IphoneDevSDk上有一个很棒的主题。
他们使用隐藏的UIWebView: http://www.iphonedevsdk.com/forum/iphone-sdk-development/61447-how-play-youtube-movie.html
答案 1 :(得分:-3)
NSString *url = @"http://www.example.com/path/to/movie.mp4";
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:url]];
[moviePlayer play];
检查并释放控制器。