Get started with jsmediatags CDN

BSD-3-Clause licensed

JsMediaTags is a lightweight library for reading ID3 tags in MP3 files.

Tags:
  • ID3
  • tags
  • mp3
  • audio
  • mp4

Stable version

Copied!

How to start using jsmediatags CDN


// Include the jsmediatags library using the CDN link
const Tag = window.Tag;
const FileReader = window.FileReader;

// Function to read ID3 tags from an audio file
async function readID3Tags(file) {
  return new Promise((resolve, reject) => {
    const reader = new FileReader();
    reader.onload = (event) => {
      const arrayBufferView = new Uint8Array(event.target.result);
      const tag = new Tag();
      tag.file = new Blob([arrayBufferView], { type: file.type });

      tag.onsuccess = function() {
        const tags = tag.tags;
        resolve(tags);
      };

      tag.onerror = function(error) {
        reject(error);
      };

      tag.read();
      tag.loadData(arrayBufferView.buffer);
    };

    reader.onerror = reject;
    reader.readAsArrayBuffer(file);
  });
}

// Function to test the example
async function test() {
  const file = new File(['path/to/your/audiofile.mp3'], 'audiofile.mp3');
  try {
    const tags = await readID3Tags(file);
    console.log(tags);
  } catch (error) {
    console.error('Error reading ID3 tags:', error);
  }
}

test();
Copied!
Copied!

All versions