【发布时间】:2019-12-12 23:56:27
【问题描述】:
我正在从画布中实例化 MediaStream。我需要将来自 Three.js 的音频流中的音频连接到此流。
我尝试了很多东西,但最简洁的是提供的代码。是否添加了流但音频只是听不见?
const context: AudioContext = ThreeAudioContext.getContext();
const destination = context.createMediaStreamDestination();
const source = context.createMediaStreamSource(destination.stream);
source.connect(destination);
stream.addTrack(destination.stream.getAudioTracks()[0]);
我也试过这个看看音频是否连接,但我还是什么都听不到。
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]);
我想听 Three.JS 的音频,但我什么也没听到。我在游戏中可以调节音量。这会影响事情吗?我应该注意我首先调用 canvas.captureStream(),然后执行这个“轨道添加”,然后实例化一个记录器。
【问题讨论】:
-
一个可运行的 sn-p 会很有帮助。你能提供一个吗?
-
@RaymondToy 感谢您的回复!我能够解决它并提供了一个可以帮助未来人们的解决方案。
标签: javascript three.js web-audio-api