首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WebMidi.js输出为空

WebMidi.js输出为空
EN

Stack Overflow用户
提问于 2018-06-29 23:58:45
回答 1查看 256关注 0票数 0

我正在尝试使用WebMidi.js在浏览器中播放便笺。我正在使用下面的代码,这些代码主要取自快速入门指南。

代码语言:javascript
复制
<body>
  <script src="node_modules/webmidi/webmidi.min.js"></script>
  <script defer>
    WebMidi.enable(function(err) {
      if (err) {
        console.log("WebMidi could not be enabled.", err);
      } else {
        console.log("WebMidi enabled!");
        console.log("outputs:", WebMidi.outputs);
      }
    });
  </script>
</body>

当我加载页面时,它说启用了WebMidi,但是输出数组是空的。如何才能让包检测到我的输出?我在Mac上使用Chrome --我的软件是最新的.

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-08-30 08:01:30

要使用MIDI输出来播放声音,您需要有一个硬件或软件MIDI合成器与虚拟MIDI端口运行。您可能希望使用AudioContext来代替:

代码语言:javascript
复制
// patch up prefixes
window.AudioContext=window.AudioContext||window.webkitAudioContext;

context = new AudioContext();
if (navigator.requestMIDIAccess)
  navigator.requestMIDIAccess().then( onMIDIInit, onMIDIReject );
else
  alert("No MIDI support present in your browser.  You're gonna have a bad time.")

// set up the basic oscillator chain, muted to begin with.
oscillator = context.createOscillator();
oscillator.frequency.setValueAtTime(110, 0);
envelope = context.createGain();
oscillator.connect(envelope);
envelope.connect(context.destination);
envelope.gain.value = 0.0;  // Mute the sound
oscillator.start(0);  // Go ahead and start up the oscillator

要生成更复杂的声音,请查看SoundJS或其他声音库。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51110657

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档