Media player playlist using PyQT
-
I've some problems making this work. I wanna use playlist to play audio files. here is my code:
playlist = QMediaPlaylist() url = QUrl.fromLocalFile("/home/user/Downloads/ss.mp3") playlist.addMedia(QMediaContent(url)) player.setPlaylist(playlist) player.playlist().setCurrentIndex(0) player.play()
The problem is that when I feed the file as unique media source (player.serMedia()) it works, but when I run the code above, the music doesn't play!
What's the problem here?
-
Hi
Disclaimer. Not a python user.Did you try to see if
QMediaPlaylist::error()
says something ?also
bool QMediaPlaylist::isEmpty() const
or
int QMediaPlaylist::mediaCount() constto see if list is actually loaded ?
-
Hmm, yes it does sound like something loaded.
You seems to do exactly as
https://meetingcpp.com/index.php/br/items/building-an-mp3-player-with-qt5.htmlIs this the same place/ code as when you test (player.setMedia())
I wonder if it runs out of scope or anything like that.
-
Hi
This works in c++void MainWindow::on_pushButton_released() { auto player = new QMediaPlayer; auto playlist = new QMediaPlaylist(player); playlist->addMedia(QUrl::fromLocalFile("e:/1.mp3")); playlist->addMedia(QUrl::fromLocalFile("e:/2.mp3")); playlist->addMedia(QUrl::fromLocalFile("e:/3.mp3")); playlist->setCurrentIndex(1); player->setPlaylist(playlist); player->play(); }
Its starts playing at once.