【问题标题】:Audio in Node-webkit using node js and Web Audio API使用 node js 和 Web Audio API 在 Node-webkit 中的音频
【发布时间】:2015-02-18 16:48:55
【问题描述】:

我正在使用 node-webkit 开发一个应用程序,我需要在其中播放音频。我已经使用 Web Audio API 和 XMLHttpRequest 成功播放了音频,但是加载歌曲非常慢。根据格式和大小,最多需要 1 秒。

有没有办法使用 node.js 文件系统加载文件,然后将该数据传递给 Web Audio API 以减少加载时间?有没有更好的方法来处理整个事情?

注意:我正在构建一个本机应用程序,因此我想播放音频而不是将其流式传输到客户端。我还需要能够对音频进行处理,这就是我研究 Web Audio API 的原因。

【问题讨论】:

    标签: javascript node.js node-webkit


    【解决方案1】:

    您可以将音频数据转换为 data: uri 并使用它。

    Check out this question for more information.

    There are a large number of tools to convert an audio file to a data uri too.

    这个 npm file-component

      var file = require('file');
      var img = file("/path/to/audio");
    
      if (!img.is('image/*')) {
        alert('Images only!');
        return;
      }
    
      var reader = img.toDataURL(function(err, str){
        if (err) throw err;
        console.log("This is a data: uri: " + str);
      });
    
      reader.on('progress', function(e){
        console.log(e.percent);
      });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-11-09
      • 2013-05-31
      • 2016-06-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-23
      • 2014-04-15
      相关资源
      最近更新 更多