MPMoviePlayerViewController 无法播放 youtube

发布于 2024-11-15 10:28:08 字数 751 浏览 2 评论 0原文

可能的重复:
使用 MPMoviePlayerController 而不是 UIWebView 播放 YouTube 视频

我使用此代码

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

但这没有用。我建议这样是错误的吗?或者有一些我想念的东西。

那么你能帮助我或指导我吗:)

Possible Duplicate:
Play YouTube videos with MPMoviePlayerController instead of UIWebView

I use this code

-(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 : )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

走走停停 2024-11-22 10:28:08
- (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 视频无法在模拟器上运行,请在设备上尝试

- (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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文