获取节点js中的音频文件持续时间和大小

时间:2016-10-06 06:24:56

标签: node.js

我正在使用节点js的musicmetadata模块来读取持续时间和大小,但它不适用于所有mp3文件。出现以下错误: -

   Error: Could not find metadata header
   at /var/www/html/Live/node_modules/musicmetadata/lib/id3v1.js:13:19
   at Stream.done (/var/www/html/Live/node_modules/musicmetadata/lib/common.js:31:5)
   at emitNone (events.js:91:20)
   at Stream.emit (events.js:185:7)
   at drain   
  (/var/www/html/Live/node_modules/musicmetadata/node_modules/through/index.js:34:23)
   at Stream.stream.queue.stream.push (/var/www/html/Live/node_modules/musicmetadata/node_modules/through/index.js:45:5)
   at Stream.end (/var/www/html/Live/node_modules/musicmetadata/node_modules/through/index.js:15:35)
   at _end (/var/www/html/Live/node_modules/musicmetadata/node_modules/through/index.js:65:9)
   at Stream.stream.end (/var/www/html/Live/node_modules/musicmetadata/node_modules/through/index.js:74:5)
   at ReadStream.onend (_stream_readable.js:512:10)
   at ReadStream.g (events.js:286:16)
   at emitNone (events.js:91:20)
   at ReadStream.emit (events.js:185:7)
   at endReadableNT (_stream_readable.js:975:12)
   at _combinedTickCallback (internal/process/next_tick.js:74:11)
   at process._tickDomainCallback (internal/process/next_tick.js:122:9)
   + Error: NODE_ENV is not defined! Using default development environment

代码示例:它包含了解问题所需的代码。

  var fs = require('fs');
  var musicData = require('musicmetadata');
 //working for "01 .Brown Rang -Mp3 Songs -[320kbps]-[Exclusive]~~~[CooL GuY] {{a2zRG}}.mp3"
  var parser = musicData(fs.createReadStream('03 RANG DE CHUNRIYA.mp3'),{ duration: true }, function (err, metadata) {
  var talkItem = {};
  if (err)
  {
    console.log('err:',err);    
  }
  else{
      if(metadata.title === undefined || metadata.title === "")
      {
        talkItem.title ='';
      }
      else{
        talkItem.title = metadata.title;
      }

      talkItem.duration = metadata.duration;
      console.log('talkItem:',talkItem);

  }

});

你可以看到代码mp3文件here

0 个答案:

没有答案