基本上我有一个背景音轨和一个播放和暂停按钮用于画外音,当你播放画外音时,背景降到0.25,当画外音停止时,它应该回到1.0。你可以在下面看到我使用的代码,它确实降低了bg音乐的音量,但当vo结束时,bg音乐保持在较低的水平。哦,如果你想知道StopBG中的if语句是试图让bg音乐只有在播放时才恢复正常的开始,有一个选项可以让它完全静默。对于那些想看一看的人来说,这个网站是here。
function PlayVO()
{
document.getElementById("vostate").value = "0";
var voAudio = document.getElementById("voiceover_audio");
var bgAudio = document.getElementById("background_audio");
bgAudio.volume = 0.25;
voAudio.volume = 1.0;
voAudio.play();
if(voAudio.ended)
{
bgAudio.volume = 1.0;
}
}
function StopVO()
{
document.getElementById("vostate").value = "1";
var voAudio = document.getElementById("voiceover_audio");
voAudio.volume = 0.0;
voAudio.pause();
voAudio.currentTime = 0;
if(voAudio.volume == 0.25)
{
bgAudio.volume = 1.0;
}
}发布于 2015-07-29 23:00:48
尝试以下操作:
//global variable
var oldBGVolume, voAudio, bgAudio;
document.onload = function(){
voAudio = document.getElementById("voiceover_audio");
bgAudio = document.getElementById("background_audio");
voAudio.addEventListener("ended", function() {
StopVO();
});
}
function PlayVO()
{
document.getElementById("vostate").value = "0";
oldBGVolume = bgAudio.volume;
bgAudio.volume = 0.25;
//If volume does not default to 1.0 keep this. Otherwise it is unneeded.
voAudio.volume = 1.0;
voAudio.play();
}
function StopVO()
{
document.getElementById("vostate").value = "1";
voAudio.pause();
voAudio.currentTime = 0;
bgAudio.volume = oldBGVolume;
}让我简单介绍一下这些变化。我将背景音量存储在全局变量oldBGVolume中。我为document.onload添加了一个函数来设置voAudio和bgAudio变量,并为ended事件添加了一个事件侦听器。一旦播放结束,就会调用StopVO函数。最后,在您的StopVO函数中,我恢复了之前的背景音频音量。
https://stackoverflow.com/questions/31703829
复制相似问题