maemo.org - Talk

maemo.org - Talk (https://talk.maemo.org/index.php)
-   Development (https://talk.maemo.org/forumdisplay.php?f=13)
-   -   How to play an mp3 sound? (https://talk.maemo.org/showthread.php?t=69143)

crabsody 2011-01-30 15:40

How to play an mp3 sound?
 
Well I just want to play an mp3 sound. Simple as that. So I read in the documentation how to do it. I wrote the following code..

QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice());
qDebug() << "Device name" << info.deviceName() << endl;

But when I run it to my N900 nothing is printed on the screen!!!
Can somebody help me with this?

laasonen 2011-01-30 16:44

Re: How to play an mp3 sound?
 
Python example playing pcm.

crabsody 2011-01-30 16:52

Re: How to play an mp3 sound?
 
As I see the developer of the example issues tha command defaultOutputDevice too. Like me. But (in my case) this returns null!!! I have just compiled my code using qt creator and adding MOBILITY += multimedia to the .pro file. When I run it using Simulator then defaultOutputDevice returns something. The same for availableCodecs and so. But when I run the maemo target using my N900 I get nothing....

laasonen 2011-01-31 07:46

Re: How to play an mp3 sound?
 
Maybe you should try phonon.

crabsody 2011-02-04 18:51

Re: How to play an mp3 sound?
 
can mafw help?

kojacker 2011-02-04 19:00

Re: How to play an mp3 sound?
 
Quote:

Originally Posted by crabsody (Post 936141)
can mafw help?

I have a tutorial about playing sounds in PyQt in my signature ('Build your own Fart App.. in 30 mins'), you can learn a lot about the basics of playing sounds with Phonon from it. I use almost exactly the same code in C++ with mFakeCaller.

For example, here's the startRingtone method Ive written for mFakeCaller:

Code:

   
void startRingtone(const QString &tonePath){
        ringTonePath = tonePath;
        mediaObject = new Phonon::MediaObject(this);
        Phonon::AudioOutput *audioOutput =
        new Phonon::AudioOutput(Phonon::MusicCategory, this);
        Phonon::Path path = Phonon::createPath(mediaObject, audioOutput);
        mediaObject->setCurrentSource(Phonon::MediaSource(tonePath));
        mediaObject->play();
        connect(mediaObject, SIGNAL(finished()), this, SLOT(repeatRingTone()));
    }

It'll play mp3s, wavs, anything Phonon can play.

Ive also created project files to help someone before on another thread. Simply replace the animal sound files with a mp3 file :D

http://i90.photobucket.com/albums/k2...016-165636.png

(Edit: bah looking at that thread again, 42 people downloaded that project and not one person thanked me for making it.. bleeeeeeh :rolleyes: )

crabsody 2011-02-04 19:34

Re: How to play an mp3 sound?
 
Thans Kojacker. I will check this out.

crabsody 2011-02-05 11:45

Re: How to play an mp3 sound?
 
Κojacker one more question. Why your wav files are not in the qrc files? I try to play some mp3 files which I have added to qrc but they don't play...

kojacker 2011-02-05 13:10

Re: How to play an mp3 sound?
 
Quote:

Originally Posted by crabsody (Post 936718)
Κojacker one more question. Why your wav files are not in the qrc files? I try to play some mp3 files which I have added to qrc but they don't play...

The only reason was because i wanted people to be able to easily replace them, inc if they didnt have Qt Creator. I think they should still play when added in the qrc resource file if it's linked correctly though.. Try running your application from Xterm and see if it's reporting any error message, ie are you getting a file not found error or something else when it tries to load the sound file?

crabsody 2011-02-05 14:02

Re: How to play an mp3 sound?
 
No. I found no errors. If I use this line

mediaObject->setCurrentSource(Phonon::MediaSource(":new/images/images/cow.mp3"))

it doesn't work

if I use this

mediaObject->setCurrentSource(Phonon::MediaSource("/home/grizos/NokiaQtSDK/Projects/Babytoy/music/cow.mp3"));

It works ok.!!!!

Very strange!! ??

kojacker 2011-02-05 14:07

Re: How to play an mp3 sound?
 
if it's in your qrc, try:

mediaObject->setCurrentSource(Phonon::MediaSource("qrc:/new/images/images/cow.mp3"))

is that path structure 'new/images/images/..' set up ok within your qrc?

gionni88 2011-02-05 14:08

Re: How to play an mp3 sound?
 
Quote:

Originally Posted by crabsody (Post 936776)
mediaObject->setCurrentSource(Phonon::MediaSource(":new/images/images/cow.mp3"))

it doesn't work

Shouldn't it be :/new/images/... etc as resource file path?

http://doc.qt.nokia.com/latest/resources.html

vkv.raju 2011-02-05 14:18

Re: How to play an mp3 sound?
 
Quote:

Originally Posted by crabsody (Post 936776)
No. I found no errors. If I use this line

mediaObject->setCurrentSource(Phonon::MediaSource(":new/images/images/cow.mp3"))

it doesn't work

if I use this

mediaObject->setCurrentSource(Phonon::MediaSource("/home/grizos/NokiaQtSDK/Projects/Babytoy/music/cow.mp3"));

It works ok.!!!!

Very strange!! ??

I am not at all into Qt programming but this is what I got from this link: http://doc.qt.nokia.com/latest/phonon-mediasource.html . If you have already looked at it, then please ignore this...

Also, did you try entering this ":new/images/images/" into your windows explorer and see where it goes? My guess is that it might not be a valid path or URL!

crabsody 2011-02-05 15:02

Re: How to play an mp3 sound?
 
It seems that this is a bug of qt 4.6

http://bugreports.qt.nokia.com/browse/QTBUG-6562


I tried this workaround:

Code:

QFile *file = new QFile(":new/images/music/cow.mp3");
mediaObject->setCurrentSource(Phonon::MediaSource(file));

But now I got this warning when I try to play the sound

Code:

MediaSource::Stream not yet handled

crabsody 2011-02-05 15:10

Re: How to play an mp3 sound?
 
Haha. Well this warning is issued only with Qt Simulator. In my N900 works fine.. Thanks to all for the help....

merajc 2011-08-07 22:13

Re: How to play an mp3 sound?
 
Hello! Apologies for replying to an old thread.

I'm facing a problem with Phonon playback as well on Maemo, but on Symbian, Desktop and Qt Simulator the following code works 100%:

Code:

//QString url;
    url = ":/new/prefix1/a.mp3";

    //Phonon::MediaObject *music;
    music = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource(url));

    //file exists, therefore exists is returned to the console
    if(QFile::exists(url))
        qDebug("exists");
    else
        qDebug("doesn't");

    //works if user selects the file:
    url = QFileDialog::getOpenFileName(this, tr("Select Music Files"), QDesktopServices::storageLocation(QDesktopServices::MusicLocation));

    music->setCurrentSource(url);

    music->play();

    //no error is being outputed
    qDebug(music->errorString().toAscii());

Basically if I allow the user to select the file himself, it plays back. If I set the file path by code, it doesn't play back.

The file is there, as I check it with an if condition.

It only doesn't work on the N900, everywhere else if plays.

Any clue to what the problem might be?

Regards
Meraj


All times are GMT. The time now is 23:25.

vBulletin® Version 3.8.8