0

I'm seeking inputs from people who have worked with Web Audio API in the react-vr. React-VR already has very cool components to place sounds in your scene, however, I need to go down one-step and access the audio buffer which is easily achieved by AudioContext provided by Web Audio.

In my client.js init() I can find the audio context in the vr instance

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; 
 }

I am struggling to figure how to expose the audio context. It's scope ends once I exit the init() function. Is there another way to access the audio context in index.vr.js?

avroshk
  • 63
  • 9

1 Answers1

0

I'm having the same issue... I can set the audio context:

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

And inside of client.js it console.logs just fine. BUT...

inside my AudioOsc module this:

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

where this.getAc is a callback (as per the reactvr docs) logs out an empty Object.

HOWEVER...

inside my AudioOsc module I can create an oscillator and connect it to a destination and it hums along just fine. So it seems to me there is actually no way to pass the context from a Native Module into ReactVR and back again... They eat the object somewhere along the way.

If things change I'd love to know! Otherwise, I think we may have to create a crap ton of audio modules on our own.

user2093532
  • 21
  • 1
  • 4