Qt : audio streaming mp3 / wav embedded in a data file

1.6k Views Asked by At

In a mobile phone application, I need to play a sound file (mp3 or wav) embedded in a data file.

Currently I need to extract the file to the SDCARD and it is quite slow.

However, in Android, I can play it inside a data file without extracting.

I requested this feature to the Qt team about 2 years ago but it seems that this function still not available.

I think I should do some streaming from the data file but lack the knowledge. Anybody has some code to enlighten me?

1

There are 1 best solutions below

1
On

I actually do not use Qt for mobile application development, but I think you can embed your audio file into resources and then just play it by Phonon module. The example how you can do this in a simple console application is below (":/fileName.mp3" is the path to the audio in the resource file). Phonon is a cross-platform multimedia framework and you also have resources on mobile platforms.

#include <QtCore/QCoreApplication>
#include <phonon>

using namespace Phonon;

int main(int argc, char *argv[])
{
    QCoreApplication a(argc, argv);

    MediaObject *music =
    createPlayer(MusicCategory,MediaSource(":/fileName.mp3"));
    music->play();

    return 0;
}