4

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

Parmanand
  • 355
  • 2
  • 6
  • 15

1 Answers1

9

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.

Arpegius
  • 5,817
  • 38
  • 53