【发布时间】:2020-11-16 04:26:10
【问题描述】:
public useAudio(base64EncodedAudio: any, loop: boolean, volume: number) {
let _this = this;
let audioFromString = this.base64ToBuffer(base64EncodedAudio);
this._context.decodeAudioData(audioFromString, function (buffer) {
_this.audioBuffer = buffer;
_this.PlaySound(loop, volume);
}, function (error) {
TelemetryClient.error(EventType.BASE64_DECODE_ERROR, "Error decoding sound string");
});
}
private PlaySound(loop: boolean, volume: number) {
this._source = this._context.createBufferSource();
let gainNode = this._context.createGain();
gainNode.gain.value = +(volume / 100).toFixed(2);
gainNode.connect(this._context.destination);
this._source.buffer = this._audioBuffer;
this._source.loop = loop;
this._source.connect(gainNode);
this._source.start(0);
}
gainNode.gain.value 似乎无法正常工作。值 1 和 0.15 以最大音量播放声音。
我这里有什么遗漏吗?
【问题讨论】:
-
请告知我们您用于进行此测试的 MS Edge 浏览器的确切版本?我同意@chrisguttandin 的建议。您是否尝试在任何其他机器上运行此代码来检查结果?如果没有,您可以进行检查并让我们知道结果可能有助于缩小问题范围。
-
不知道是否相关,但您将字符串设置为值。
标签: google-chrome microsoft-edge html5-audio web-audio-api