ios - 我不想在 UIWebview 中自动播放 play youtube video

标签 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 中一样。当我点击那个按钮时,我只需要播放视频。请给我任何想法...

最佳答案

我在 embedHTML 中找到了我的答案 a.target.playVideo(); 我把它改成了 a.target.pauseVideo(); 它工作正常....

关于ios - 我不想在 UIWebview 中自动播放 play youtube video,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20344439/

相关文章:

ios - 使用 AVCaptureSession 以编程方式捕获最高分辨率图像

javascript - 为什么我的 YouTube 链接不能在 Chrome 的 iframe 中自动播放?

ios - Facebook 登录与 Swift 崩溃问题

ios - 是否可以从根 UISplitController 推送 UIVIEWCONTROLLER?

iOS 核心数据分组方式

iphone - 加载桌面版网站

ios - 两个 UIWebView 之间的翻转动画

iphone - UIWebView 中的 PDF

javascript - 使用jQuery将声音从静音更改为取消静音

Youtube 嵌入了 watch_popup 并且没有建议的视频