PDA

View Full Version : Phonon and file's metadata



matulik
30th March 2011, 23:58
Hello.
I want to create a simple music player based on phonon libraries.
In my GUI I've a tablewidget. It's working at music list.
But I don't know how to read values ARTIST or TITLE from files metadata to take it to tablewidget after "open files" operation.

I've a
QList<Phonon::MediaSource> files; to keep music files in my program. Now, I want to their metadata valuse like this:


mediaObject->setCurrentSource(files[index]);
QMap<QString, QString> metaData = mediaObject->metaData();
QString title = metaData.values("TITLE");


But it doesn't works...

Anybody know how to help my?

high_flyer
31st March 2011, 09:53
Note that meta data is not resolved before the metaDataChanged() signal is emitted.
Did you make sure that you code metadata code runs after metaDataChanged() was emitted?

TobyYi
7th February 2012, 07:02
Well, We must emit a signal metaDataChanged(),it can get the information for title.

brezel
9th May 2012, 15:35
hi!

i seem to be having kinda the same problem...did you ever get it to work? i own the book 'advanced qt programming' which has a code example showing how to get metadata from files, but also that doesn't work :( the only way i could read metadata from the mediaObject so far, is, if i call mediaObject->play(); and in the slot handling the emitted stateChanged signal do mediaObject->metaData(), then mediaObject->stop().

the example code (http://www.qtrac.eu/aqpbook.tar.gz) has a timer waiting for 1 second for the stateChanged(Phonon::State, Phonon::State) signal after mediaObject.setCurrentSource(source);, but it seems like it is never emitted. could this be a bug in Phonon or am i misunderstandig the way this should work?

in my desparation i even tried:



localMediaObject.setCurrentSource(source);
connect(this, SIGNAL(xxx), &localMediaObject, SIGNAL(metaDataChanged()));
emit xxx();
if (!waitForMediaObjectToLoad(&localMediaObject, OneSecond))
return;
...

but that also didn't work. any pointers?

spinax
9th May 2012, 18:48
connect(localMediaObject, SIGNAL(metaDataChanged()), this, SLOT(yourfunction()));

brezel
9th May 2012, 20:05
connect(localMediaObject, SIGNAL(metaDataChanged()), this, SLOT(yourfunction()));

i don't get it...i have just tried that exact same code:


localMediaObject = new Phonon::MediaObject(this);
Phonon::MediaSource source(filename);
connect(localMediaObject, SIGNAL(metaDataChanged()), this, SLOT(addTrack()));
localMediaObject->setCurrentSource(source);

but my addTrack method is never called :| thanks for replying anyway