Question

When I type the following code in Python, the song.mp3 doesn't play. Why??

output = Phonon.AudioOutput(Phonon.MusicCategory) 
m_media = Phonon.MediaObject() 
Phonon.createPath(m_media, output) 
m_media.setCurrentSource(Phonon.MediaSource("files/song.mp3")) 
m_media.play() 
Was it helpful?

Solution

You need QApplication or QCoreApplication instance and you have to launch event loop with exec() member after m_media.play(). Phonon::MediaObject::play is asynchronous.

C++ example

QApplication app(argc, argv);
// phonon initialization, and play
app.exec()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top