Using a resource file in QMediaPlayer

喜欢而已 提交于 2020-01-02 07:06:20

问题


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.


回答1:


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 "...".



来源:https://stackoverflow.com/questions/30084109/using-a-resource-file-in-qmediaplayer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!