Open iframe video in fullscreen programmatically

醉酒当歌 提交于 2021-01-29 14:33:22

问题


I open youtube video using iframe in webview. It shows default control buttons for video including fullscreen button. How can I call function of fullscreen button by myself? For example, I want go to fullscreen on landscape, but videos open in fullscreen only by tap on fullscreen button or while first loading. I need go to fullscreen while playing video.


回答1:


Hope you are using YTPlayer for YouTube Videos. If not you can find the player here - GithubLink

For YTPlayer, there's a parameter playsinline. To always play fullscreen, you need to set the playsinline property to 0. Something like:

 let playerVars = [
    "playsinline" : 0
  ]
  player.loadWithVideo(id:movieURL, playerVars:playerVars)



回答2:


I have found function. There is webkitEnterFullScreen in webkit's video tag: https://developer.apple.com/documentation/webkitjs/htmlvideoelement

So all I need is to get video and execute function through javascript:

playerView.webView?.evaluateJavaScript("document.getElementById('player').contentDocument.getElementsByClassName('video-stream')[0].webkitEnterFullScreen()") { object, error in
       print(error)
}


来源:https://stackoverflow.com/questions/59331905/open-iframe-video-in-fullscreen-programmatically

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