"Fullscreen is unavailable" 将 YouTube 视频作为 iframe 嵌入到 QWebEngineView 中
"Fullscreen is unavailable" embedding YouTube videos as iframe in QWebEngineView
我正在尝试在 QWebEngineView 中嵌入 YouTube 视频,视频加载正常,但全屏按钮被禁用并显示此消息 "Fullscreen is unavailable" 即使嵌入代码确实有 "allowfullscreen"
代码片段:
web = QWebEngineView()
htmlString = """
<iframe width="560" height="315" src="https://www.youtube.com/embed/L0MK7qz13bU?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
"""
web.setHtml(htmlString, QUrl(baseUrl))
要启用全屏,需要启用页面的 FullScreenSupportEnabled attribute and accept the fullScreenRequested 顺序。
if __name__ == '__main__':
app = QApplication(sys.argv)
web = QWebEngineView()
web.settings().setAttribute(QWebEngineSettings.FullScreenSupportEnabled, True)
web.page().fullScreenRequested.connect(lambda request: request.accept())
baseUrl = "local"
htmlString = """
<iframe width="560" height="315" src="https://www.youtube.com/embed/L0MK7qz13bU?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
"""
web.setHtml(htmlString, QUrl(baseUrl))
web.show()
sys.exit(app.exec_())
截图:
我正在尝试在 QWebEngineView 中嵌入 YouTube 视频,视频加载正常,但全屏按钮被禁用并显示此消息 "Fullscreen is unavailable" 即使嵌入代码确实有 "allowfullscreen"
代码片段:
web = QWebEngineView()
htmlString = """
<iframe width="560" height="315" src="https://www.youtube.com/embed/L0MK7qz13bU?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
"""
web.setHtml(htmlString, QUrl(baseUrl))
要启用全屏,需要启用页面的 FullScreenSupportEnabled attribute and accept the fullScreenRequested 顺序。
if __name__ == '__main__':
app = QApplication(sys.argv)
web = QWebEngineView()
web.settings().setAttribute(QWebEngineSettings.FullScreenSupportEnabled, True)
web.page().fullScreenRequested.connect(lambda request: request.accept())
baseUrl = "local"
htmlString = """
<iframe width="560" height="315" src="https://www.youtube.com/embed/L0MK7qz13bU?rel=0&showinfo=0" frameborder="0" allowfullscreen></iframe>
"""
web.setHtml(htmlString, QUrl(baseUrl))
web.show()
sys.exit(app.exec_())
截图: