2017-05-04 21 views
3

這已經發布幾年了,但仍然沒有得到解決。我決心使一些在音量播放視頻,讓我們說150%,但HTML5體積法與任何值的誤差大於1 https://www.w3schools.com/tags/av_prop_volume.aspHTML5增長過去100%

這裏是我的代碼:

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

0.5有效,但不是1.5。一個答案說,它給這個錯誤:

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

無論如何,我可以做一些與此異常要跑它超出了範圍[0,1]?

回答

6

視頻音量是0到1之間的百分比,它不能高於100%。

您可能會發生這種情況的唯一方法是將音頻從視頻播放器路由到Web Audio API並在那裏放大。

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); 

您可以從視頻音頻方面並運行它通過增益節點,以提高音量或類似應用混響音效。注意不要太多增加增益節點的增益,或者已經掌握的音頻將開始削波。

最後,您需要將增益節點連接到音頻目標,以便它可以輸出新的音頻。