Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Phonon class not present in PyQt5

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

like image 983
Parmanand Avatar asked Jan 10 '23 12:01

Parmanand


1 Answers

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.

like image 88
Arpegius Avatar answered Jan 13 '23 00:01

Arpegius