Phonon class not present in PyQt5

前端 未结 1 582
一个人的身影
一个人的身影 2021-01-06 12:36

I am using PyQt5 version to develop simple Audio player but it\'s fail to import Phonon class.

I want to play simple mp3 file

Hope to hear from you soon

相关标签:
1条回答
  • 2021-01-06 13:03

    There is no Phonon in Qt5. New QtMultimedia module should be used:

    import PyQt5.QtCore as C
    import PyQt5.QtMultimedia as M
    import sys
    
    app=C.QCoreApplication(sys.argv)
    
    url= C.QUrl.fromLocalFile("./some.mp3")
    content= M.QMediaContent(url)
    player = M.QMediaPlayer()
    player.setMedia(content)
    player.play()
    
    player.stateChanged.connect( app.quit )
    app.exec()
    

    Before you ask, you need PyQt5.QtMultimedia module, witch might not be provided with PyQt5 Core library. Ubuntu have separated packed python3-pyqt5.qtmultimedia.

    0 讨论(0)
提交回复
热议问题