Code Monkey home page Code Monkey logo

Comments (6)

Borewit avatar Borewit commented on May 23, 2024 1

Better to use the build File/Blob parser, that will take the right mime-type from the browser.

mm.parseBlob(file, { duration: true }).then(metadata => {});

from music-metadata-browser.

Borewit avatar Borewit commented on May 23, 2024
describe('272', () => {

  it('Parse: duration-parse-problem.m4a', async () => {

    const filePath = path.join(issue_path, '#272', 'duration-parse-problem.m4a');

    const metadata = await mm.parseFile(filePath);
    const {format} = metadata;

    assert.strictEqual(format.container, 'M4A/iso2/isom');
    assert.isAtLeast(format.duration, 0, 'format.duration');
    assert.deepEqual(format.tagTypes, ['iTunes']);

    console.log(JSON.stringify(format, null, 2))
  });
});

passes and outputs:

{
  "tagTypes": [
    "iTunes"
  ],
  "container": "M4A/iso2/isom",
  "duration": 226.717,
  "sampleRate": 44100,
  "bitsPerSample": 16,
  "numberOfChannels": 2,
  "lossless": false,
  "bitrate": 64040.085216371066,
  "codec": "MPEG-4/AAC"
}

Maybe you gave me the wrong file?

from music-metadata-browser.

lopaz avatar lopaz commented on May 23, 2024

@Borewit I tried it with music-metadata directly, the result was correct. Sorry for not testing before post this issue.
I came accross with this problem while using [email protected]

I've got a file tag in html, when it's value changes, handleFileChange function would be called.
Here's my code, it works perfect with mp3 files.

function handleFileChange(e) {
    var file = e.target.files[0];
    var reader = new FileReader();
    reader.onload = function(e) {
      var data = e.target.result;
      var Buffer = require("buffer/").Buffer;
      var buffer = Buffer.from(data);
      mm.parseBuffer(buffer, "audio/mpeg", { duration: true }).then(
          metadata => {
             //...
          }
        );
    };
    reader.readAsArrayBuffer(file);
  }

from music-metadata-browser.

Borewit avatar Borewit commented on May 23, 2024

Sorry for not testing before post this issue.

No problem, I appreciate you took the effort to report your issue.

I downloaded your sample file and dragged it into audio-tag-analyzer (which is currently using music-metadata-browser v1.6.0), seems to extract the duration correct.

Screenshot from 2019-09-27 10-13-02

I did not have the opportunity yet to look into you code fragment.

from music-metadata-browser.

lopaz avatar lopaz commented on May 23, 2024

I noticed that the 'File Type' on your snapshot image was different from which I used. After some tests, I found out the reason:
I use mm.parseBuffer(buffer, "audio/mpeg", { duration: true }) for parsing mp3 files, which is correct. When the same code used to parse acc files, the duration would be negative. I checked the docs again, and saw that music-metadata would try to guess the MIME-type when not provided or not understood, so I changed the code to mm.parseBuffer(buffer, "", { duration: true }), it worked for both mp3 files and acc files.
Thanks for your help. @Borewit

from music-metadata-browser.

microvn avatar microvn commented on May 23, 2024

I think it might return 0 if not using the duration option.
https://www.mediafire.com/file/tb9e7xnj1kjxdnb/Doja_Cat_-_Say_So_%2528Audio%2529.aac/file

from music-metadata-browser.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.