aadsm / jsmediatags

Media Tags Reader (ID3, MP4, FLAC)
Other
745 stars 128 forks source link

URL.createObjectURL(file) #118

Closed strukturart closed 4 years ago

strukturart commented 4 years ago

Hello, I is possible to use URL.createObjectURL(file) to read out the metadata ?

Error message: Error: No suitable file reader found for blob:app://{9d3f6e1c-7dd9-4875-9b12-19f78a862775}/8a4deaa3-afbf-4f42-8d38-d5010022fce6

Code snippet

cursor.onsuccess = function () {
        if(cursor.result) 
        {
            var file = cursor.result;

            if(file.type.match('audio/*'))
            {

                fileURL = URL.createObjectURL(file)

                if(jsmediatags)
                {

                jsmediatags.read(fileURL, {
                    onSuccess: function(tag) {
                    console(tag);
                },
                    onError: function(error) {
                    console(':(', error.type, error.info);
                    }
                });

                }
Borewit commented 4 years ago

I am not sure if I understand exactly what you want. I assume you want to read from a File (which is also a Blob)

music-metadata-browser can read the Blob/file using parseBlob:

const musicMetadata = require('music-metadata-browser');

// No need for: fileURL = URL.createObjectURL(file)

musicMetadata.parseBlob(file).then(metadata => {
  // do something with the metadata
});

Demo: https://audio-tag-analyzer.netlify.com/

strukturart commented 4 years ago

I had writen an musicplayer app for the nokia8110(KaiOS) https://github.com/strukturart/audio It works but the filenames are not nice to read(12092019_podcast.mp3), so I wanted to read the metatags. Do you think I should do it with music-metadata-browser ?

Borewit commented 4 years ago

I have no experience with Nokia apps. music-metadata-browser is designed for module based browser application. It's very complete, very robust, but larger then jsmediatags. With music-metadata-browser you need a module bundler like webpack. jsmediatags on the other hand has a pre-bundled distribution.

strukturart commented 4 years ago

Thank you it works with music-metadata-browser.

Borewit commented 4 years ago

Note that the musicmetadata.js you copied into your project is not the same as music-metadata-browser. Although it has common roots, it is a predecessor module of years back. Just like jsmediatags, it included the pre-bundled distribution you copied. If your project grows larger you want to use module bundler, which basically enables you to manage your dependencies via npm, and build your own distribution with everything you need. One of the many benefits is that it prevent duplicate dependencies. Copying files will also belong to the past.