Search code examples
c++qtformatqt5qmediaplayer

How to save pls file in QMediaPlaylist instead of m3u


Actually, I try in QTCreator to save a playlist into a multitude of format.

QTCreator save and load without problems the m3u format.

It either load a .pls file I written by hand, but it can't save a similar pls format (It create an empty "playlst.pls").

I used the example showed from this manual: http://doc.qt.io/qt-5/qmediaplaylist.html#save

The code save the playlist in pls format, the file is created, but empty.

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Player setting
    player = new QMediaPlayer;
    connect(player, SIGNAL(positionChanged(qint64)),
            this, SLOT(positionChanged(qint64)));
    player->setMedia(QUrl::fromLocalFile("/home/batfly/MilkyWay.mp3"));
    player->setVolume(50);
    player->play();

    // Configure playlist:
    playlist = new QMediaPlaylist;
    playlist->addMedia(QUrl("file:///home/batfly/MilkyWay.mp3"));
    playlist->addMedia(QUrl("file:///home/batfly/Gurdil.mp3"));
    playlist->addMedia(QUrl("file:///home/batfly/OwenWasHere.mp3"));
    playlist->setCurrentIndex(1);


    // Set playlist on player:
    player = new QMediaPlayer;
    player->setPlaylist(playlist);

    // Save playlist:
    playlist->save(QUrl::fromLocalFile
                   ("/home/batfly/playlisttest.pls"),"pls");

    videoWidget = new QVideoWidget;
    player->setVideoOutput(videoWidget);
    videoWidget->show();


    player->play();
}

Where is the problem? QTCreator can't save into pls format, or I forget something?

Thank you!

PS: I add more information about my problem: - I'm working in Linux (Debian 9.X). - I use QTCreator 4.2, the last version have some bugs actually, so I don't update and keel the apt install version of Debian.


Solution

  • It's more accurate to put my comment as an answer. I do this to close this old question and show this as an answer. After all, there was no evolution from QT since 2019, so this answer is still valid:

    After a deeper look (and help from others):
    The save function in the file QMediaPlaylist.cpp shows the format parameter depending on the plugins.

    I tried to get the plugin folder, and I see a libqtmultimedia_m3u.so, the unique file of the playlistformat folder, but not any libqtmultimedia_pls.so plugin.

    I can't find this file or another format from the internet...

    Conclusion: QTCreator can't save any other formats than m3u, in 2019 at least. I made the plsCreator file myself.