以编程方式全屏打开

以编程方式全屏打开

本文介绍了以编程方式全屏打开 iframe 视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 webview 中使用 iframe 打开 youtube 视频.它显示视频的默认控制按钮,包括全屏按钮.如何自己调用全屏按钮的功能?例如,我想在横向模式下进入全屏模式,但视频只能通过点击全屏按钮或在首次加载时以全屏模式打开.我需要在播放视频时进入全屏模式.

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.

推荐答案

我找到了函数.webkit 的视频标签中有 webkitEnterFullScreen:https://developer.apple.com/documentation/webkitjs/htmlvideoelement

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

所以我只需要通过javascript获取视频和执行功能:

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)
}

这篇关于以编程方式全屏打开 iframe 视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 09:14