@rocka/mp3-duration
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

mp3-duration Travis-Build

Calculate duration of an MP3

Install

npm install mp3-duration

Usage

  1. JavaScript
var mp3Duration = require('@rocka/mp3-duration');

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

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

API

mp3Duration(filePathOrBuffer [, cbrEstimate])

filePathOrBuffer

Type: string | Buffer

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

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

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

License

MIT © Han de Boer

Package Sidebar

Install

npm i @rocka/mp3-duration

Weekly Downloads

117

Version

2.0.0

License

MIT

Unpacked Size

8.76 kB

Total Files

5

Last publish

Collaborators

  • rocka