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.
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 "..."
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With