Search code examples
qtmetadataqmediaplayer

How to get metadata of all media in QMediaPlaylist?


I'm working on a Ubuntu qt project which implements a media player. Since QMediaObject::metaData can just get current media's metadata, i want to know if there is a way to get metadata of all songs which I added in QMediaPlaylist to add to a table. Any help is appreciated.


Solution

  • Qt Multimedia only supports querying the current songs's metadata. One possibility is to load all songs one at the time, query the metadata when the status is QMediaPlayer::LoadedMedia (connect to mediaStatusChanged() signal) and isMetaDataAvailable() returns true, and then close the media and move to the next one.

    If you want to have metadata of all audiofiles beforehand you need to use some other library or framework which scans through the media files and creates a "metadata database" for you which you then utilize when showing the list of all songs.

    One possible solution is to write a Python script which uses Mutagen module for retrieving the metadata. It supports ASF, FLAC, MP4, Monkey’s Audio, MP3, Musepack, Ogg Opus, Ogg FLAC, Ogg Speex, Ogg Theora, Ogg Vorbis, True Audio, WavPack, OptimFROG, and AIFF audio files. All versions of ID3v2 are supported, and all standard ID3v2.4 frames are parsed.

    You can google for help to write the script, e.g. How do I access these ID3 values using Python and Mutagen , Accessing mp3 Meta-Data with Python

    When you add a new song to a playlist you either load the song through QMediaPlayer to query its metadata or launch a script which queries the metadata and adds to the "metadata database".