pyQT4 Web 浏览器 Python 授予权限(网络摄像头) [英] pyQT4 Web Browser Python grant permission (webcam)

查看:80
本文介绍了pyQT4 Web 浏览器 Python 授予权限(网络摄像头)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要制作一个非常简单的用 python 包装的网络浏览器.我为此使用 pyQt4.我可以很容易地创建一个小浏览器来加载网页,几乎一切正常.我遇到的问题是无法访问网络摄像头.导航到任何尝试访问网络摄像头的 url(通过 javascript getUserMedia() )什么都不做.甚至不提示用户选择网络摄像头设备.

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.

这是为什么?

如何通过简单的 pyQT4 python 程序授予使用网络摄像头的权限?

How do I grant permission to use the webcam with a simple pyQT4 python program?

这是我目前所拥有的:

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_())

此代码加载 webrtc 演示,应立即提示访问网络摄像头.但事实并非如此.所有要求网络摄像头权限的网站都不起作用.

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.

推荐答案

QtWebKit 仅支持 地理位置和通知作为权限请求.

QtWebKit only supports Geolocation and Notifications as permission requests.

我认为它根本不支持 WebRTC,您可能想要升级到 PyQt5 并使用 QtWebEngine 代替.

I don't think it supports WebRTC at all, you might want to upgrade to PyQt5 and use QtWebEngine instead.

这篇关于pyQT4 Web 浏览器 Python 授予权限(网络摄像头)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆