问题描述
我知道使用 Video JS 库将音频提升超过 100% 的唯一方法是使用增益节点设置一个稍微有点卡顿的自定义音频上下文。
这使得更改播放速率不起作用。我知道 player.tech()
并不是真的要使用,但似乎这是提高音量的唯一方法。
我在这里做错了什么吗?如果是这样,既能将音量提高到 100 以上又能控制播放速率的最佳方法是什么?
const normal = videojs('normal',{ "playbackRates": [1,4] });
const boosted = videojs('boosted',4],enableSourceset: true });
boosted.on("sourceset",() => {
const context = new window.AudioContext();
const gain = context.createGain();
context.createMediaElementSource(boosted.tech().el()).connect(gain);
gain.connect(context.destination);
gain.gain.value = 10;
});
使用 VideoJS:
https://codepen.io/qhyun2/pen/gOgPKqP
没有:
https://codepen.io/qhyun2/pen/abpZmMB
解决了!
解决方法
您需要从点击处理程序中resume()
AudioContext
。以下应该有效。
const context = new window.AudioContext();
const boosted = videojs(
'boosted',{
enableSourceset: true,playbackRates: [1,4]
}
);
boosted.on("play",() => context.resume());
boosted.on("sourceset",() => {
const gain = context.createGain();
context.createMediaElementSource(boosted.tech().el())
.connect(gain)
.connect(context.destination);
gain.gain.value = 10;
});
但是它在 codepen.io 上不起作用。视频文件未提供必要的 CORS 标头。