Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using a resource file in QMediaPlayer

How do I load a .mp3 file to use in a QMediaPlayer from a .qrc resource file?

This is what I have so far

QMediaPlayer *player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile(":/audio/theme.mp3"));
player->play();

resources.qrc:

<RCC>
    <qresource prefix="/audio">
        <file>theme.mp3</file>
    </qresource>
</RCC>

theme.mp3 is located in the project directory.

like image 416
Oskar Persson Avatar asked May 06 '15 17:05

Oskar Persson


1 Answers

Use m_player->setMedia(QUrl("qrc:/audio/theme.mp3"));

If you are using Qt Creator, you can copy this url to clipboard by pressing right button on the audio file in the side bar and choosing Copy url "...".

like image 163
rsht Avatar answered Oct 09 '22 14:10

rsht