【问题标题】:Accessing Web Audio Context in React VR在 React VR 中访问 Web 音频上下文
【发布时间】:2018-04-03 04:40:03
【问题描述】:

我正在寻求在 react-vr 中使用过 Web Audio API 的人的意见。 React-VR 已经有非常酷的组件可以在场景中放置声音,但是,我需要一步一步访问音频缓冲区,这可以通过 Web Audio 提供的 AudioContext 轻松实现。

在我的 client.js init() 我可以在 vr 实例中找到音频上下文

function init(bundle, parent, options) {   
   const vr = new VRInstance(bundle, 'WelcomeToVR', parent, {
      ...options,   
   });

  audioCtx = vr.rootView.context.AudioModule.audioContext._context; //HERE

  vr.render = function() { };   
  vr.start();

  return vr; 
 }

我正在努力弄清楚如何公开音频上下文。一旦我退出 init() 函数,它的作用域就结束了。是否有其他方法可以访问 index.vr.js 中的音频上下文?

【问题讨论】:

  • vr 会返回到哪里?该对象在您的 vr 代码中不可用吗?

标签: web-audio-api react-360


【解决方案1】:

我也有同样的问题...我可以设置音频上下文:

audioOsc._setAudioContext(vr.rootView.context.AudioModule.audioContext._context;)

在 client.js 内部,它的 console.logs 就好了。但是……

在我的 AudioOsc 模块中:

AudioOsc.getAudioContext(this.getAc, this.getAc);

其中 this.getAc 是一个回调(根据 reactvr 文档)注销一个空对象。

但是...

在我的 AudioOsc 模块中,我可以创建一个振荡器并将其连接到一个目的地,它会一直嗡嗡作响。所以在我看来,实际上没有办法将上下文从 Native Module 传递到 ReactVR 并再次返回......他们在途中的某个地方吃掉了这个对象。

如果事情发生变化,我很想知道!否则,我认为我们可能不得不自己创建大量的音频模块。

【讨论】:

    猜你喜欢
    • 2019-01-25
    • 1970-01-01
    • 2012-03-16
    • 2015-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-20
    • 1970-01-01
    相关资源
    最近更新 更多