QtMultimedia MP3 audio playback

和自甴很熟 提交于 2019-12-11 06:08:28

问题


I want to play an audio (MP3) file when the QmainWindow opens and have used the script from here. This is what my code looks like:

app = QApplication(sys.argv)

window = MainWindow()
window.show()

url = QUrl.fromLocalFile("./sound2.mp3")
content = QMediaContent(url)
player = QMediaPlayer()
player.setMedia(content)
player.play()

player.stateChanged.connect(app.quit)

app.exec_()

There is no problem running the script except that when I close the app the MP3 sound file continues to play when it should in fact stop. How do I modify the code? Thanks in advance.

来源:https://stackoverflow.com/questions/43018205/qtmultimedia-mp3-audio-playback

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!