maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   N900 QMediaPlayer (https://talk.maemo.org/showthread.php?t=64598)

tmsha 2010-10-28 20:48

N900 QMediaPlayer
 
I got this bit of code that I run on a N900 with PR1.3 Qt4.7 Mobility 1.0.2

Code:

QMediaPlayer *player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile("ballhit.wav"));
player->setVolume(50);
player->play();



When I run it, this happends:

GStreamer; Unable to play – “file:ballhit.wav”

I think that it may not find the file, I have tried many different methods of adding the wav file to my project, but none seems to work, I don’t know what is the best approach.
If i replace “ballhit.wav” with for example: ”Http://tst.com/b.wav”, it works, no problem.
But I can’t load my sound files from the web, I want them on the device.

Developing on windows with Qt Creator.

Please help me :)

jamie721 2010-10-28 21:24

Re: N900 QMediaPlayer
 
have you tryed adding it to the qrc file. im no expert but i do that with all my graphics befor i load them. This i think imbeds them in the executable tho which means its not optifyed. so before uploading to extras or testing you will have to work out how to load them from file and add them to the opt folder for your app.

What i know is in a browser you would use file:// to access a local file instead of a remote webservers file.

but if i am loading a image from file in qt i would pass the string ":sprites/image.png"

sprites being the folder in the src directory that holds the images.

image.png being the image in the folder.

for you this would be something like ":sounds/sounds1.wav"

or maybe "file://sounds/sound1.wav"

tmsha 2010-10-28 21:36

Re: N900 QMediaPlayer
 
Thank you, I have tried to add the file to my resource file, and also tried all your suggestions, but it still does not work.

uvatbc 2010-10-28 21:39

Re: N900 QMediaPlayer
 
Quote:

Originally Posted by tmsha (Post 855841)
I got this bit of code that I run on a N900 with PR1.3 Qt4.7 Mobility 1.0.2

Code:

QMediaPlayer *player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile("ballhit.wav"));
player->setVolume(50);
player->play();



When I run it, this happends:

GStreamer; Unable to play – “file:ballhit.wav”

I think that it may not find the file, I have tried many different methods of adding the wav file to my project, but none seems to work, I don’t know what is the best approach.
If i replace “ballhit.wav” with for example: ”Http://tst.com/b.wav”, it works, no problem.
But I can’t load my sound files from the web, I want them on the device.

Developing on windows with Qt Creator.

Please help me :)

I had this problem, and the only way I could fix it was to do the following:
Code:

QFileInfo info (path);
if (!info.exists ()) {
    // error out
}
QString strFullname = info.absoluteFilePath ();
player.setMedia (QUrl::fromLocalFile(strFullname));


tmsha 2010-10-28 21:44

Re: N900 QMediaPlayer
 
thank you :D I will try it

tmsha 2010-10-28 21:53

Re: N900 QMediaPlayer
 
I did the following:

Code:

QFileInfo info("ballhit.wav");
QString strFullname = info.absoluteFilePath ();
QMediaPlayer *player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile(strFullname));

It does not work...
info.exists()
and
info.isFile()
both returns false... :(

How did you include your file with the project?

uvatbc 2010-10-28 23:05

Re: N900 QMediaPlayer
 
Quote:

Originally Posted by tmsha (Post 855943)
I did the following:

Code:

QFileInfo info("ballhit.wav");
QString strFullname = info.absoluteFilePath ();
QMediaPlayer *player = new QMediaPlayer;
player->setMedia(QUrl::fromLocalFile(strFullname));

It does not work...
info.exists()
and
info.isFile()
both returns false... :(

How did you include your file with the project?

Where is ballhit.wav with respect to your executable binary?
Is it in the same directory? Then try "./ballhit.wav"

Use QFileInfo::exists to find out if your executable binary exists where you think it does. How do you execute your app? Do you do it from the same directory as the wave file?
The "." in "./ballhit.wav" typically means "current directory" which is the directory in which you started running your app.

Edit:
Also: My media files are generated on the fly. So my case isn't exactly like yours.

tmsha 2010-10-28 23:20

Re: N900 QMediaPlayer
 
Thank you for your replay.

I have found the path of the executable to be: ”/usr/local/bin/” but there is no “ballhit.wav” in that dir.

I can go to that dir and do ./app and it runs like normal, but the sounds does not work.


I did a “find . -name “ballhit.wav”” with root and found nothing on the phone.
So, the file has not been copied ?
How can I ensure the file is copied and installed with the executable?
I think that is my problem.. I need to copy the file over to the phone when i run it from Qt Creator.

I have done the following in an attempt to fix it:

In the same folder as src.pro i got ballhit.wav, and in src.pro i added this:

OTHER_FILES += ballhit.wav

target.path = $$DESTDIR
target.files += ballhit.wav
INSTALLS += target

I have also added a build step: “make install”

uvatbc 2010-10-28 23:33

Re: N900 QMediaPlayer
 
Quote:

Originally Posted by tmsha (Post 855976)
Thank you for your replay.

I have found the path of the executable to be: ”/usr/local/bin/” but there is no “ballhit.wav” in that dir.

I can go to that dir and do ./app and it runs like normal, but the sounds does not work.


I did a “find . -name “ballhit.wav”” with root and found nothing on the phone.
So, the file has not been copied ?
How can I ensure the file is copied and installed with the executable?
I think that is my problem.. I need to copy the file over to the phone when i run it from Qt Creator.

I have done the following in an attempt to fix it:

In the same folder as src.pro i got ballhit.wav, and in src.pro i added this:

OTHER_FILES += ballhit.wav

target.path = $$DESTDIR
target.files += ballhit.wav
INSTALLS += target

I have also added a build step: “make install”

See my pro file line 173 onwards.

"target" is a tag for your executable binary.
Any additional files that you want installed need to come with additional tags. In my pro file, these additional tags for my maemo5 binary are "desktop" "icon" "qss" etc.

After defining that INSTALLS needs to have extra tags, I also specified where the files in every tag should fall (tag.path) and what the source file is on my dev machine (tag.files).

Once you do all that, your deb should have everything you need.
Also: once you actually build your deb, its a good idea to go into the debian sub directory and see the directory structure in there to confirm that the deb-helpers have done what you wanted.

Remember that a deb is a compressed archive of:
1. All the files you said need to be installed (binary, media files, whatever else)
2. Control scripts to pick up things from a deb and put them into the correct corresponding locations on the user machine
3. Dependency and other meta information

tmsha 2010-10-28 23:54

Re: N900 QMediaPlayer
 
Thank you so much! That is exactly what I was looking for (I think).
I remember using code like that in my pro file when I was working on scratchbox :)
I will try it out now!

tmsha 2010-10-29 00:10

Re: N900 QMediaPlayer
 
It worked! :D Thank you so much! I have been at this for hours..

I miss a better way to handle this with Qt...

But, really, thank you uvatbc :) You made my day :D

uvatbc 2010-10-29 00:27

Re: N900 QMediaPlayer
 
Quote:

Originally Posted by tmsha (Post 856008)
I miss a better way to handle this with Qt...

I completely sympathize: I wasted about a week and almost gave up on the Nokia QT SDK trying to do debian-ization.

When (not if) you start getting pissed about making a script to "auto-build and upload" your app, have a look at the perl scripts I've created to make my life simpler.

Be warned of course, that those perl scripts are still fundamentally "broken" because they upload to the non-free repos, even though the source is actually LGPL and up there on Google Code.
I haven't got enough patience or motivation to fix that.
Once you get there for your app, tell me how you did it.

tmsha 2010-10-29 00:45

Re: N900 QMediaPlayer
 
I will have a look, thank you for the heads up.
I will report back when I get that far :)


All times are GMT. The time now is 17:28.

vBulletin® Version 3.8.8