【发布时间】:2017-05-13 09:04:04
【问题描述】:
我想在网络上使用 PyQt5 的 QWebEngineView 播放音频。这是我的代码:
import sys
from PyQt5 import QtWebEngineWidgets, QtWidgets
if __name__ == '__main__':
app = QtWidgets.QApplication([])
view = QtWebEngineWidgets.QWebEngineView()
view.settings().setAttribute(QtWebEngineWidgets.QWebEngineSettings.PluginsEnabled, True)
view.settings().setAttribute(QtWebEngineWidgets.QWebEngineSettings.JavascriptEnabled, True)
html = '''
<html>
<audio id="pron" src="http://static.sfdict.com/staticrep/dictaudio/A06/A0612000.mp3"></audio>
<button onclick="document.getElementById('pron').play()">Play!</button>
</html>'''
view.setHtml(html)
view.resize(250, 150)
view.move(300, 300)
view.show()
sys.exit(app.exec_())
但是当我点击Play 按钮时,音频没有播放。我怎么了?
【问题讨论】:
-
“苹果!”在linux上对我来说很好。设置没有区别。如果您使用的是 Windows,您是否安装了所有必要的音频编解码器?尝试使用指向 wma 文件的链接进行测试。
-
与@ekhumoro 意见相同
-
我在测试您的示例时收到控制台警告,即 js: Uncaught (in promise) NotSupportedError: The element has no supported sources.
标签: python pyqt pyqt5 qwebengineview