I want to play audio on the web use QWebEngineView of PyQt5. This is my code:
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_())
But when I click the Play
button, the audio not play. What's wrong with me?