MPMoviePlayerViewController无法播放youtube

时间:2011-06-14 05:20:07

标签: objective-c ios video youtube mpmovieplayercontroller

  

可能重复:
  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];
}

但它无效。我建议这个感冒是错的吗?或者有一些我想念的东西。

所以,你能帮我或指导我吗?)

2 个答案:

答案 0 :(得分: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 vidoes我们必须使用我使用的嵌入式代码,它的工作正常.youtube视频无法在模拟器上运行尝试在设备上

答案 1 :(得分:0)