MP3 file from Resources :-/
Hi!
How can I use a mp3 file from Resources ? I have tried the following code but without any success. I would appreciate if someone could shed some light on how to play audio files from the resource qrc file. Thanks !
Code:
QString location
= ":/kalimba.mp3";
m_mediaObject = new Phonon::MediaObject(this);
// Setup player
m_videoWidget = new Phonon::VideoWidget(this);
Phonon::createPath(m_mediaObject, m_videoWidget);
setCentralWidget(m_videoWidget);
//m_audioOutput = new Phonon::AudioOutput(Phonon::VideoCategory, this);
m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
m_audioOutput->setVolume(100.0);
Phonon::createPath(m_mediaObject, m_audioOutput);
QObject::connect(m_mediaObject,
SIGNAL(stateChanged
(Phonon
::State,Phonon
::State)),
this,
SLOT(stateChanged
(Phonon
::State,Phonon
::State)));
//m_mediaObject->setCurrentSource(Phonon::MediaSource(QUrl::fromEncoded(location.toUtf8())));
m_mediaObject->setCurrentSource(Phonon::MediaSource(location.toUtf8()));
m_mediaObject->play();
}
The qrc file:
Code:
<RCC>
<qresource prefix="/">
<file>kalimba.mp3</file>
</qresource>
</RCC>
Re: MP3 file from Resources :-/
have you checked if the code works if you specify a mp3 file from your disk (for debugging purpose)?
Re: MP3 file from Resources :-/
Yes the code works fine with a local mp3 file.
Code:
QString location
= "/Users/pat/Documents/QT_projects/PhononMp3-build-desktop/kalimba.mp3";
Is the resources qrc file the only way to get a media file embedded with the executable file ?
Re: MP3 file from Resources :-/
Did anyone encountered the same problem ? I am testing on the mac platform...
MediaSource recognizes only absolut paths ? isn't it possible to have only :
The mp3 file is inside the build desktop directory
Thanks
Added after 55 minutes:
This works works if I include the mp3 file into the phonon.app/Contents/MacOS directory:
Code:
Phonon::MediaObject *music = createPlayer(Phonon::MusicCategory,
Phonon::MediaSource("kalimba.mp3"));
music->play();
My problem with an audio file within the qrc file is still not resolved. Any help would be appreciated :confused:
Re: MP3 file from Resources :-/
Quote:
Originally Posted by
qtpat
My problem with an audio file within the qrc file is still not resolved. Any help would be appreciated :confused:
And it still causes trouble ...
got it to work on Windows with qrc, but only in Qt Creator -_-
on Mac only local files, no qrc (app ran outside of qt creator, also with QMediaPlayer)
Re: MP3 file from Resources :-/
Hi,
I have the same problem, have you found any solution ?
thank you