Search code examples
reactjsaudiocontexthowler.js

React and HowlerJS: Howler.ctx is null


I am trying to expose the AudioContext api in the global Howler and assign it to a variable, however I am unable to figure out how to get Howler.ctx to not be null.

const CTX = Howler.ctx ; // Howler.ctx is returning null

Solution

  • The AudioContext doesn't get setup in howler.js until a Howl is created. However, you can trick it into creating one by calling one of the following, which will in turn call the internal setupAudioContext method:

    Howler.mute(false);
    Howler.volume(1);