Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here is a version for mp3 and m4a.</p> <pre><code>#include &lt;mpegfile.h&gt; #include &lt;attachedpictureframe.h&gt; #include &lt;id3v2tag.h&gt; #include &lt;mp4file.h&gt; #include &lt;mp4tag.h&gt; #include &lt;mp4coverart.h&gt; #include &lt;iostream&gt; class ImageFile : public TagLib::File { public: ImageFile(const char *file) : TagLib::File(file) { } TagLib::ByteVector data() { return readBlock(length()); } private: virtual TagLib::Tag *tag() const { return 0; } virtual TagLib::AudioProperties *audioProperties() const { return 0; } virtual bool save() { return false; } }; int main(int argc, char *argv[]) { if (argc != 3) { std::cout &lt;&lt; "Usage: setcover &lt;mp3|m4a&gt; cover.jpg" &lt;&lt; std::endl; return 1; } TagLib::String fileName = argv[1]; TagLib::String fileType = fileName.substr(fileName.size() - 3).upper(); ImageFile imageFile(argv[2]); if (fileType == "M4A") { // read the image file TagLib::MP4::CoverArt coverArt((TagLib::MP4::CoverArt::Format) 0x0D, imageFile.data()); // read the mp4 file TagLib::MP4::File audioFile(argv[1]); // get the tag ptr TagLib::MP4::Tag *tag = audioFile.tag(); // get the items map TagLib::MP4::ItemListMap itemsListMap = tag-&gt;itemListMap(); // create cover art list TagLib::MP4::CoverArtList coverArtList; // append instance coverArtList.append(coverArt); // convert to item TagLib::MP4::Item coverItem(coverArtList); // add item to map itemsListMap.insert("covr", coverItem); tag-&gt;save(); //audioFile.save(); } else if (fileType == "MP3") { TagLib::MPEG::File audioFile(argv[1]); TagLib::ID3v2::Tag *tag = audioFile.ID3v2Tag(true); TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame; frame-&gt;setMimeType("image/jpeg"); frame-&gt;setPicture(imageFile.data()); tag-&gt;addFrame(frame); audioFile.save(); } else { std::cout &lt;&lt; fileType &lt;&lt; " is unsupported." &lt;&lt; std::endl; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload