i loading website contains videos. using wkwebview loading these videos. need stop videos autoplay when loading pages, added following java script code pause video.
nsstring *script = @"var videos = document.queryselectorall(\"video\"); (var = videos.length - 1; >= 0; i--) { videos[i].pause(); };"; [webview evaluatejavascript:script completionhandler:^(id result, nserror *error) { nslog(@"error : %@",error.localizeddescription); nslog(@"java script result = %@",result); }]; i can able pause video in of websites listing cnn, youtube etc. not working websites. example :
theglobe&mail - http://www.theglobeandmail.com/news/news-video/
bbc - http://www.bbc.com/news/video_and_audio
is there solution issue?
there property in ios 9.0 wkwebview called requiresuseractionformediaplayback if set true, autoplay should turned off
if using < ios 9.0, set property mediaplaybackrequiresuseraction true turn off autoplay.
i didnt yet try on websites mentioned. update answer once do
Comments
Post a Comment