PDA

View Full Version : Harmattan QUrl and QMediaPlayer problem with source



andzero
9th December 2011, 05:51
Hi!
I'd post this thread in embedded section,
but i consider this as a newbie question xD
so i'm sorry if this is the wrong section.

Okay, as the title says: In my application I'm trying to use QMediaPlayer to play music in my app, for Harmattan target.
The sound files are included via deploymentfolders.

From PC, it is already working: (in Qt Simulator)

playlist->addMedia(QUrl::fromLocalFile("/files/sound_1.mp3"))

However, it's not working when installed in the device.
I've been going back and forth with QA because of this, because I don't have a device to test :(
and I think Harmattan QEMU and RDA doesnt give me sound output because Angry Birds has no sound.

Things I've tried:
- I noticed that the default working directory when I run the app is not in my application directory, so I've set it with

QDir::setCurrent("/opt/myapp/") by adding this code, the device can now read my textfiles ( with QFile )
however QUrl still don't seem to work.

-I've tried to write the absolute path of the file with:

playlist->addMedia(QUrl::fromLocalFile(QDir::current().path( ) + QString("/files/sound_1.mp3")));
and still won't work.

Please help.

Big thanks!

ChrisW67
9th December 2011, 07:17
Your first code snippet is looking for a file at an absolute location (because of the leading '/') on the machine. I presume that location is not correct.

Your second code snippet changes the current working directory of the process, but this will have no effect if you continue to request a file with an absolute path.

Your third code snippet should find a file relative to the current working directory of the process (you could just use currentPath()), but is the current working directory where you think it is? If the file is installed and can be located relative to the executable then you should try: QCoreApplication::applicationDirPath() rather than relying on the current working directory.

If this file is a permanent part of your application then you should consider building it into the executable using the Qt resource system.