Best way to get Media MetaData?
-
hello,
In my mp3 player app's add song function, I want to read mp3 files from url and save their title, url, album, artist to a model and display it to view.
I have tried using another QMediaPlayer in this funtion to read meta data but it too slow (mediaStatus alway LoadingMedia not LoadedMedia).
Is there any other way to read meta data from file url? -
@NguyenMinh have you tried some external library, like TagLib or id3lib?
-
@Pablo-J.-Rogina This project is actually a homework so I can't use external library
-
Hi,
What exactly are you allowed to use ?
-
@NguyenMinh said in Best way to get Media MetaData?:
QMediaPlayer in this funtion to read meta data but it too slow
Can you show how you're using it?
-
@jsulm I want to do it in a function so I try something like this:
void addSong(){ QMediaPlayer *player=new QMediaPlayer; player->setMedia(QUrl("C:/Users/Public/Music/Sample Music/music1.mp3")); QStringList metadatalist = player->availableMetaData(); qDebug()<<metadatalist; {
This will fail because setMedia take time to load the file so metadatalist will be a blank string.
-
@NguyenMinh Yes you can't do it like this. Qt is assynchronous.
Actually, you can use https://doc.qt.io/qt-5/qmediaobject.html
Connect a slot to https://doc.qt.io/qt-5/qmediaobject.html#availabilityChanged signal and read meta data there if parameter is true.
Maybe https://doc.qt.io/qt-5/qmediaobject.html#metaDataChanged is of interest as well. -
@NguyenMinh You can use QMediaObject directly as I suggested - should be cheap enough :-)
-
@NguyenMinh You're right. Looks like you have to use QMediaPlayer.