The Web Audio API, available in THEOplayer version 2.19.4 and onward, allows you to reroute the audio output of THEOplayer to a Web Audio context. This is done by providing a Web Audio source node which outputs the player's audio. Using Web Audio allows developers to apply a variety of effects and transformations to the player's audio output, e.g. equalization, volume normalization, ...
The following methods are accessible via
audioCtx : AudioContext
Creates an AudioNode object embedded in the given AudioContext which can serve as a SourceNode. As a consequence of calling this method, audio playback from the player will be re-routed into the processing graph of the provided AudioContext.
The way the Web Audio standard was designed has a few consequences:
- Once the player has created an AudioNode within a given AudioContext, you must connect it to an output node in the graph, directly or indirectly, or the output will be silent. The flow of audio from the created node has to reach an output node, one way or another. Of course, the player's output can pass through an arbitrary number of intermediary nodes before it reaches an output node.
- Once the player's is rerouted, there is no way back: the audio cannot be released from its AudioContext, as Web Audio specifies no way to release audio resources which are piped through. This means that you cannot change the AudioContext of the output node, nor can you stop piping the player audio to Web Audio. In a well-designed Web Audio setup, this should not matter, as there should be exactly one AudioContext per page, and there should be no need to stop piping to Web Audio.
Due to technical limitations, not all the audio can be rerouted using Web Audio. Notably, Google IMA ads do not allow their audio to be rerouted, and therefore will not pass through the Web Audio graph as specified by the developer.