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 !
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();
}
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();
}
To copy to clipboard, switch view to plain text mode
The qrc file:
<RCC>
<qresource prefix="/">
<file>kalimba.mp3</file>
</qresource>
</RCC>
<RCC>
<qresource prefix="/">
<file>kalimba.mp3</file>
</qresource>
</RCC>
To copy to clipboard, switch view to plain text mode
Bookmarks