HTML5卷增加100% [英] HTML5 Volume Increase Past 100%

查看:76
本文介绍了HTML5卷增加100%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这已经在几年前发布,但仍未解决。我决定制作能够以150%的音量播放视频的内容,但HTML5音量方法的错误值大于1.
https://www.w3schools.com/tags/av_prop_volume.asp

This has been posted a few years back, but has still gone unresolved. I'm determined to make something that plays the video at a volume let's say 150%, but HTML5 volume method has an error with any value greater then 1. https://www.w3schools.com/tags/av_prop_volume.asp

这是我的代码:

javascript:(function(){document.getElementsByTagName('video')[0].volume = 1.5;}());

0.5有效但不是1.5。一个答案说它给出了这个错误:

0.5 works but not 1.5. One answer said that it gives this error:

Uncaught DOMException: Failed to set the 'volume' property on 'HTMLMediaElement': The volume provided (2) is outside the range [0, 1].

无论如何,我可以对此例外做些什么让它超出范围[0,1]? ?

Anyway I can do something with this exception to have it run beyond the range [0,1]??

推荐答案

视频音量是0到1之间的百分比,不能高于100%。

The video volume is a percentage between 0 and 1, it can't got higher than 100%.

您可能实现这一目标的唯一方法是将音频从视频播放器路由到Web Audio API并在那里放大。

The only way you could potentially make this happen is be routing the audio from the video player into the Web Audio API and amplifying it there.

https://developer.mozilla.org/ en-US / docs / Web / API / AudioContext / createMediaElementSource

// create an audio context and hook up the video element as the source
var audioCtx = new AudioContext();
var source = audioCtx.createMediaElementSource(myVideoElement);

// create a gain node
var gainNode = audioCtx.createGain();
gainNode.gain.value = 2; // double the volume
source.connect(gainNode);

// connect the gain node to an output destination
gainNode.connect(audioCtx.destination);

您可以从视频中获取该音频上下文并通过增益节点运行它以提升音量或应用混响等音频效果。小心不要过多地增加增益节点上的增益或者已经掌握的音频将开始削波。

You can take that audio context from the video and run it through a gain node to boost the audio volume or apply audio effects like reverb. Careful not to increase the gain on the gain node too much or audio that's already been mastered will start clipping.

最后,您需要将增益节点连接到音频目的地这样它就可以输出新的音频。

Finally, you need to connect the gain node to an audio destination so that it can output the new audio.

这篇关于HTML5卷增加100%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆