问题
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