PDA

View Full Version : MP3 file from Resources :-/



qtpat
24th November 2010, 11:40
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::fromEnc oded(location.toUtf8())));
m_mediaObject->setCurrentSource(Phonon::MediaSource(location.toUt f8()));

m_mediaObject->play();


}

The qrc file:


<RCC>
<qresource prefix="/">
<file>kalimba.mp3</file>
</qresource>
</RCC>

Lykurg
24th November 2010, 14:48
have you checked if the code works if you specify a mp3 file from your disk (for debugging purpose)?

qtpat
25th November 2010, 19:01
Yes the code works fine with a local mp3 file.


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 ?

qtpat
26th November 2010, 15:02
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 :


QString location = "kalimba.mp3"

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:


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:

McYh
29th August 2013, 19:05
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)

clebail
26th March 2014, 16:34
Hi,

I have the same problem, have you found any solution ?

thank you