我不想在UIWebview播放youtube视频中自动播放

时间:2013-12-03 06:35:34

标签: ios uiwebview youtube

ideoView = [[UIWebView alloc] initWithFrame:CGRectMake(60, 20, 200, 184)];
    videoView.delegate = self;
    videoView.scrollView.bounces = NO;
    videoView.allowsInlineMediaPlayback = YES;
    videoView.mediaPlaybackAllowsAirPlay = YES;
    videoView.mediaPlaybackRequiresUserAction = NO;
    [self.view addSubview:videoView];

    NSString* embedHTML = [NSString stringWithFormat:
                           @"<html><body style='margin:0px;padding:0px;'><script type='text/javascript'src='http://www.youtube.com/iframe_api'></script><script type='text/javascript'>function onYouTubeIframeAPIReady(){ytplayer=new YT.Player('playerId',{events:{onReady:onPlayerReady}})}function onPlayerReady(a){ a.target.playVideo(); }</script><iframe id='playerId' type='text/html' width='%@' height='%@'src='http://www.youtube.com/embed/%@?enablejsapi=1&rel=0&playsinline=1&controls=1&showinfo=1' frameborder='0'></body></html>", [NSString stringWithFormat:@"%d", 200], [NSString stringWithFormat:@"%d", 184], url];
    [videoView loadHTMLString:embedHTML baseURL:nil];

它的工作正常但它会自动播放。但在完成播放视频后,它会显示播放按钮再次播放。我需要在webview中播放按钮,就像在youtube中第一次一样。当我点击该按钮时,我只需要播放视频。请建议我任何想法...

3 个答案:

答案 0 :(得分:2)

我在 embedHTML 中发现我的ans有选项a.target.playVideo();我将其更改为a.target.pauseVideo();它工作正常....

答案 1 :(得分:0)

去扔这个网址,然后替换你的“NSString * embedHTML”值。 工作正常。

Embed youtube video in iOS App

答案 2 :(得分:0)

如何设置

videoView.mediaPlaybackRequiresUserAction = NO;

改为YES?