【问题标题】:MPMoviePlayerViewController can't play youtube [duplicate]MPMoviePlayerViewController 无法播放 youtube [重复]
【发布时间】:2011-09-14 10:16:24
【问题描述】:
可能重复:
Play YouTube videos with MPMoviePlayerController instead of UIWebView
我用这个代码
-(void)viewDidLoad
{
[super viewDidLoad];
NSString *movieURL = @"http://www.youtube.com/watch?v=hH4sHqDEjSg";
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:[NSURL URLWithString:movieURL]];
moviePlayer.moviePlayer.shouldAutoplay = YES;
[self presentMoviePlayerViewControllerAnimated:moviePlayer];
[moviePlayer release];
}
但它没有用。我建议这个喜欢是错误的?或者有什么我想念的。
所以请你帮助我或指导我:)
【问题讨论】:
标签:
objective-c
ios
video
youtube
mpmovieplayercontroller
【解决方案1】:
- (void)viewDidLoad {
[self embedYouTube:@"http://www.youtube.com/watch?v=1Xqn5IHbusA" frame:CGRectMake(65,37,45,45)];
- (void)embedYouTube:(NSString *)urlString frame:(CGRect)frame {
NSString *embedHTML = @"\
<html><head>\
<style type=\"text/css\">\
body {\
background-color: transparent;\
color: white;\
}\
</style>\
</head><body style=\"margin:0\">\
<embed id=\"yt\" src=\"%@\" type=\"application/x-shockwave-flash\" \
width=\"%0.0f\" height=\"%0.0f\"></embed>\
</body></html>";
NSString *html = [NSString stringWithFormat:embedHTML, urlString, frame.size.width, frame.size.height];
UIWebView *videoView = [[UIWebView alloc] initWithFrame:frame];
[videoView loadHTMLString:html baseURL:nil];
[self.view addSubview:videoView];
[videoView release];
}
MPMoviePlayerViewController 不播放 youtube 视频,我们必须使用我使用的嵌入代码,它工作正常。YouTube 视频不在模拟器上运行,请在设备上尝试