Reading and writing playlist files for an audio player application

Hi there. Is there any example or library you would suggest to create and use playlist files?
I made an audio player. The music file paths are stored in a string array and when playlist is saved as file, a txt file includes these paths is created.
I want to read&write m3u files and display mp3 tags such as song name, artist name, cover etc. So what do you suggest?

You have two choices, 1) find and use an existing m3u library, or 2) write your own code for reading/writing m3u files. Doing just a quick search I didn’t find any c/c++ libraries for this, but there is certainly plenty of reference code in github projects (like vlc → m3u.c). There is also the wiki page for the spec.

I realize this is a very high level answer, did you have some specific questions regarding the process?


Thanks. I have noticed that there is a member named metadataValues in juce_AudioFormatReader.h at 245th line. Can I get song name or artist name information using AudioFormatReader object?

    /** A set of metadata values that the reader has pulled out of the stream.

        Exactly what these values are depends on the format, so you can
        check out the format implementation code to see what kind of stuff
        they understand.
    StringPairArray metadataValues;

Taglib worked for me in terms of reading music file metadata including images from mp3 files.

1 Like

Thanks. Now I’ve tried reading metadata with taglib and it seems it will be very useful to use taglib for me. Now there is only one issue in my code, I can read metadata from mp3 files, but works only If they are in the same directory (current working directory) with my player.exe file. I read metadata and return them with this function:

juce::String getMetadata(const char* d)
  TagLib::FileRef f(d);
  juce::String tagExport;

  if (!f.isNull() && f.tag()) {

      TagLib::Tag* tag = f.tag();
      TagLib::String title = tag->title(),
      artist = tag->artist(),

      tagExport.append(title.toCString(), title.size() + 1);
      tagExport.append(artist.toCString(), artist.size()+1);
      tagExport.append("\n", 1);
      tagExport.append(album.toCString(), album.size()+1);
      tagExport.append("\n", 1);
      return tagExport;

const char* c = filePath.c_str();
juce::String metadata = getMetadata(c);

filePath is std::string and stores full path name of the file.