声音功能 -
function sound(src) {
this.sound = document.createElement("audio");
this.sound.src = src;
this.sound.setAttribute("preload", "auto");
this.sound.setAttribute("controls", "none");
this.sound.style.display = "none";
document.body.appendChild(this.sound);
this.play = function(){
this.sound.play();
}
this.stop = function(){
this.sound.pause();
}
}
将声音放入 -
flying = new sound("flying.wav");
渲染声音 -
flying.play()
我想知道的是,无论如何都要让wav的音量上升?
你只需要与volume
property元素的audio
进行交互。
这是我使用的文件中的一个示例函数,它为用户提供了一个向上和向下按钮,可以通过.1
在任一方向上调整音量,并确保它们最终不会将其设置为超出范围的值。这是非常不言自明的。
function adjustVolume(increment) {
// Get the proposed new volume level and check that it
// is between 0 and 1 (inclusive) or you will throw an error.
var proposedV = audioElement.volume + increment;
if (proposedV >= 0 && proposedV <= 1) {
audioElement.volume = proposedV;
}
}