I have a MediaStream created from a canvas and I am trying to add audio to it from the Three.js audio stream.
After attempting various methods, I found that the most concise solution is shown in the code snippet below. The stream seems to be added successfully, but the audio is not audible.
const context: AudioContext = ThreeAudioContext.getContext();
const destination = context.createMediaStreamDestination();
const source = context.createMediaStreamSource(destination.stream);
source.connect(destination);
stream.addTrack(destination.stream.getAudioTracks()[0]);
Even after trying another approach to check if the audio is connected properly, I still cannot hear anything.
const context: AudioContext = ThreeAudioContext.getContext();
const destination = context.createMediaStreamDestination();
const source = context.createMediaStreamSource(destination.stream);
const gainNode = context.createGain();
gainNode.gain.value = 1;
source.connect(gainNode);
gainNode.connect(destination);
stream.addTrack(destination.stream.getAudioTracks()[0]);
Although I want to listen to audio from Three.js, there's no sound coming through. Is the volume adjustment setting within the game affecting this? It's worth mentioning that I'm first calling `canvas.captureStream()`, then adding the track, and finally instantiating a recorder.