How to use the music-metadata function in music-metadata

To help you get started, we’ve selected a few music-metadata examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github olivernyc / static / src / Editor / index.js View on Github external
let type = "FILE";
      if (IMAGE_TYPES.indexOf(file.type) !== -1) {
        type = "IMAGE";
      } else if (AUDIO_TYPES.indexOf(file.type) !== -1) {
        type = "AUDIO";
      } else if (VIDEO_TYPES.indexOf(file.type) !== -1) {
        type = "VIDEO";
      } else if (PDF_TYPES.indexOf(file.type) !== -1) {
        type = "PDF";
      }

      const t = this;

      // this is ridiculous
      if (type === "AUDIO") {
        musicmetadata(file, function(err, metadata) {
          const { title, artist, album, picture, date } = metadata.common;
          let pictureBlob;
          if (picture && picture.length > 0 && picture[0]) {
            pictureBlob = URL.createObjectURL(
              new Blob([picture[0].data], {
                type: "image/" + picture[0].format
              })
            );
          }
          const contentStateWithEntity = editorState
            .getCurrentContent()
            .createEntity(type, "IMMUTABLE", {
              file: file,
              name: file.name,
              type: file.type,
              size: file.size,