Search code examples
c++qtmp3qmediaplayer

How to upload Mp3 files on Qt (QMediaPlayer)?


I have to create a Qt application that executes mp3 files. I use the library QMediaPlayer, how can I let the user choose and upload the mp3 file?


Solution

  • QMediaPlayer has a setMedia method which can accept a path to you local .mp3 file. It can be used like this.

    QMediaPlayer *player = new QMediaPlayer;
    player->setMedia(QUrl::fromLocalFile("C:\mycoolsong.mp3"));
    

    I guess you want to build something like a file explorer from where the user can select from multiple songs. There is a great tutorial for this here: C++ Qt 49 - QFileSystemModel a simple file explorer example