问题
I need to make a very simple web browser wrapped in python. I am using pyQt4 for this. I can very easily create a little browser to load web pages and almost everything works fine. The issue I am having is that accessing the webcam does not work. Navigating to any url that attempts to access the webcam (through javascript getUserMedia() ) does nothing. Doesn't even prompt for the user to select a webcam device.
Why is this?
How do I grant permission to use the webcam with a simple pyQT4 python program?
Here is what I have so far:
from PyQt4 import QtCore, QtGui, QtWebKit
class myWindow(QtWebKit.QWebView):
def __init__(self, parent=None):
super(myWindow, self).__init__(parent)
#self.page().mainFrame().addToJavaScriptWindowObject("myWindow", self)
self.loadFinished.connect(self.on_loadFinished)
self.page().featurePermissionRequested.connect(self.permissionRequested)
self.load(QtCore.QUrl('https://pubnub.com/developers/demos/webrtc'))
@QtCore.pyqtSlot()
def on_loadFinished(self):
#self.page().mainFrame().evaluateJavaScript(getJsValue)
def permissionRequested(self, frame, feature):
self.page().setFeaturePermission(frame, feature, QWebPage.PermissionGrantedByUser)
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
app.setApplicationName('myWindow')
main = myWindow()
main.show()
sys.exit(app.exec_())
This code loads a webrtc demo which should immediately prompt for webcam access. But it does not. All websites that ask for webcam permissions do not work.
Note: I tried to define permission request and then grant access. However, it still does nothing. I could be doing something wrong here?
Thanks for any help you guys can provide. Appreciate it.
回答1:
QtWebKit only supports Geolocation and Notifications as permission requests.
I don't think it supports WebRTC at all, you might want to upgrade to PyQt5 and use QtWebEngine instead.
来源:https://stackoverflow.com/questions/36854868/pyqt4-web-browser-python-grant-permission-webcam