开发者

MPMoviePlayerViewController can't play youtube [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Play YouTube videos with MPMoviePlayerController instead of UIWebView

I use this cod开发者_Python百科e

-(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];
}

But It didn't work. I suggest this likg is wrong ? or there's something I miss.

So Could you help me or Guide me please : )


- (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 not playing youtube vidoes we have to use embeded code i used and its works fine.youtube videos not run on simulator try in on device

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜