I dont want auto play the in UIWebview play youtube video

梦想与她 提交于 2019-12-24 11:08:58

问题


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

Its works fine but it play automatically. but after finish play the video it shows play button to play again. I need that play button in webview like in youtube in first time itself. While I click that button then only I need to play the video. please Suggest me any idea...


回答1:


I found my ans in embedHTML there is option a.target.playVideo(); I changed that into a.target.pauseVideo(); it works fine....




回答2:


Go threw this url and just replace your "NSString* embedHTML" value. its working fine.

Embed youtube video in iOS App




回答3:


How about setting

videoView.mediaPlaybackRequiresUserAction = NO;

to YES instead?



来源:https://stackoverflow.com/questions/20344439/i-dont-want-auto-play-the-in-uiwebview-play-youtube-video

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!