JSPM

music-duration

1.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 36
  • Score
    100M100P100Q54807F
  • License MIT

Get the duration of a music file

Package Exports

  • music-duration

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (music-duration) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

music-duration Travis-Build

Calculate duration of a music file

Only .mp3 at this moment

TODO

  • FLAC
  • WAV
  • OGG

Install

npm i music-duration

Usage

  1. JavaScript
let musicDuration = require('music-duration');

musicDuration('file.mp3')
  .then(duration => {
    console.log(`Your file is ${duration} seconds long`);
  })
  .catch(e => {
    console.err(e);
  });
  1. TypeScript
import musicDuration = require('music-duration');

musicDuration('file.mp3')
  .then(duration => {
    console.log(`Your file is ${duration} seconds long`);
  })
  .catch(e => {
    console.err(e);
  });

API

musicDuration(filePathOrBuffer [, fileType, cbrEstimate])

filePathOrBuffer

Type: string | Buffer

Path to the file or a buffer with the file's contents

fileType

Type: string

Defaults to '.mp3'.

cbrEstimate

Type: boolean

Defaults to false. When set to true, will estimate the length of a constant-bitrate mp3. This speeds up the calculation a lot but isn't guaranteed to be accurate.

Return value

musicDuration returns a Promise that resolves to the duration of the fileType in second or rejects with some error.

License

MIT Licence