wang February 2016

how can i auto play a video in my app using wkwebview

I am using wkwebview to show my site. and my site have a video. when the site is showed,the video cannot this any method to let video auto play?


Abhishek Sharma February 2016

Following function worked for me for giving support of auto play

- (void)loadwebViewToPlay {

    NSString * videoHtml = @"<html><head><style>body{margin:0px 0px 0px 0px;}</style></head> <body> <div id=\"player\"></div> <script> var tag = document.createElement('script'); tag.src = ''; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag); var player; function onYouTubePlayerAPIReady() { player = new YT.Player('player', { width:'200', height:'200', videoId:'bHQqvYy5KYo', events: { 'onReady': onPlayerReady } }); } function onPlayerReady(event) {; } </script> </body> </html>";

    UIWebView * webview = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
    webview.backgroundColor = [UIColor clearColor];
    webview.opaque = NO;
    //videoView.delegate = self;
    [self.view addSubview:webview];
    webview.mediaPlaybackRequiresUserAction = NO;

    [webview loadHTMLString:videoHtml baseURL:[[NSBundle mainBundle] resourceURL]];


For more help you can reference iframe_api_reference OR player_parameters

Post Status

Asked in February 2016
Viewed 2,629 times
Voted 7
Answered 1 times


Leave an answer