Created
April 14, 2018 06:03
-
-
Save wwj718/e00ff12ef84a8171a5537ee0a4c0e1fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://stackoverflow.com/questions/48676566/grant-access-to-cam-mic-using-python-for-pyqt-webengine | |
from PyQt5.QtWidgets import QApplication | |
from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage | |
from PyQt5.QtCore import QUrl | |
class WebEnginePage(QWebEnginePage): | |
def __init__(self, *args, **kwargs): | |
QWebEnginePage.__init__(self, *args, **kwargs) | |
self.featurePermissionRequested.connect(self.onFeaturePermissionRequested) | |
def onFeaturePermissionRequested(self, url, feature): | |
if feature in (QWebEnginePage.MediaAudioCapture, | |
QWebEnginePage.MediaVideoCapture, | |
QWebEnginePage.MediaAudioVideoCapture): | |
self.setFeaturePermission(url, feature, QWebEnginePage.PermissionGrantedByUser) | |
else: | |
self.setFeaturePermission(url, feature, QWebEnginePage.PermissionDeniedByUser) | |
app = QApplication([]) | |
view = QWebEngineView() | |
page = WebEnginePage() | |
view.setPage(page) | |
view.load(QUrl("https://test.webrtc.org/")) | |
view.show() | |
app.exec_() |
#!/usr/bin/env python
# encoding: utf-8
#from PyQt5.QtWidgets import QApplication
#from PyQt5.QtWebEngineWidgets import QWebEngineView, QWebEnginePage
#from PyQt5.QtCore import QUrl
import sys
from PySide2.QtCore import QUrl
from PySide2.QtGui import QIcon
from PySide2.QtWidgets import (QApplication, QDesktopWidget, QLineEdit,
QMainWindow, QPushButton, QToolBar)
from PySide2.QtWebEngineWidgets import QWebEnginePage, QWebEngineView
class WebEnginePage(QWebEnginePage):
def __init__(self, *args, **kwargs):
QWebEnginePage.__init__(self, *args, **kwargs)
self.featurePermissionRequested.connect(self.onFeaturePermissionRequested)
def onFeaturePermissionRequested(self, url, feature):
if feature in (QWebEnginePage.MediaAudioCapture,
QWebEnginePage.MediaVideoCapture,
QWebEnginePage.MediaAudioVideoCapture):
self.setFeaturePermission(url, feature, QWebEnginePage.PermissionGrantedByUser)
else:
self.setFeaturePermission(url, feature, QWebEnginePage.PermissionDeniedByUser)
app = QApplication([])
view = QWebEngineView()
page = WebEnginePage()
view.setPage(page)
view.load(QUrl("file:///Users/wwj/mylab/changxue/scratch-gui/build/index.html"))
view.show()
app.exec_()
pyqt5 无法使用scratch3 music插件 pyside2正常
pyside2一些有趣的例子
http://code.qt.io/cgit/pyside/pyside-setup.git/plain/examples/multimedia/player.py
http://code.qt.io/cgit/pyside/pyside-setup.git/plain/examples/charts/audio.py
http://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples/multimedia/camera.py
http://code.qt.io/cgit/pyside/pyside-setup.git/plain/examples/texttospeech/texttospeech.py 说话和声音控制
view.load(QUrl("https://operasoftware.github.io/bb8/")) 无法打开web bluetooth : navigator.bluetooth
chrome 56之后支持 Blink内核
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
基于pyside2: http://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples/webenginewidgets
pyside2更多例子: http://code.qt.io/cgit/pyside/pyside-setup.git/tree/examples
pip install --index-url=http://download.qt.io/snapshots/ci/pyside/5.11/latest/ pyside2 --trusted-host download.qt.io