ios - How do I make UIWebView pause/play video content programmatically -


i making app load youtube video through uiwebview need able have pause , play @ times. have looked @ answers here , none of them working. have tried this:

webview.stringbyevaluatingjavascriptfromstring("var videos = document.queryselectorall(\"video\"); (var = videos.length - 1; >= 0; i--) { videos[i].pause(); };") 

but nothing. if matters, loading video this:

webview.allowsinlinemediaplayback = true webview.mediaplaybackrequiresuseraction = false      let embededhtml = "<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='0' height='0' src='http://www.youtube.com/embed/\(videoid)?enablejsapi=1&rel=0&playsinline=1&autoplay=1' frameborder='0'></body></html>"  webview.loadhtmlstring(embededhtml, baseurl: nsbundle.mainbundle().resourceurl) 

as not_a_bot linked, using ytplayer.pausevideo() , ytplayer.playvideo() works perfectly.

webview.stringbyevaluatingjavascriptfromstring("ytplayer.pausevideo()") 

or

webview.stringbyevaluatingjavascriptfromstring("ytplayer.playvideo()") 

Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -