【发布时间】:2011-11-29 13:12:06
【问题描述】:
这是新代码。还是没有声音。
这个在外部js文件中 功能播放声音(颜色){ var mySound = new buzz.sound("/sounds/"+color, { 格式:[“ogg”、“mp3”、“acc”] });
mySound.play()
这在头脑中:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js">
</script>
<script type="text/javascript" src="/sounds/buzz.js">
</script>
<script type="text/javascript" src="sound.js">
</script>
<script type="text/javascript" src="hoverBubbles.js">
</script>
我已经对我的网站进行了编程,以便在用户单击图像时播放声音。我用 JS 做到了这一点。但有一个问题。在您单击图像之后,声音播放前有大约 5 秒的长时间延迟。我该怎么做才能使声音播放不延迟?另外,当我试图解决上述问题时,我做了一些事情(我不知道它是什么),我现在根本无法播放声音。
有什么想法吗?
function playSound(color) {
$("#wavLoader").html("<embed src='/sounds/" + color + ".wav' hidden=true starttime='00:00' autostart=true loop=false>");
});
}
<title>Colors</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js">
</script>
<script type="text/javascript" src="hoverBubbles.js"></script>
<script type="text/javascript" src="sound.js"></script>
<link rel="stylesheet" type="text/css" href="heading.css">
<link rel="stylesheet" type="text/css" href="fish.css">
<link rel="stylesheet" type="text/css" href="fishText.css">
<link rel="stylesheet" type="text/css" href="fishBubbles.css">
<style type='text/css'>
</style>
$(document).ready(function() {
$('#fishBlack').mouseover(function() {
$('#bubblesBlack').toggle('slow');
$('#textBlack').toggle('slow');
});
$('#fishBlack').mouseout(function() {
$('#bubblesBlack').hide('slow');
$('#textBlack').toggle('slow');
});
}
$(document).ready(function() {
$('#fishBlack').click(function() {
playSound('black');
});
}
<!--the sound-->
<span id="wavLoader" style="position:fixed; top:-100px;"></span>
【问题讨论】:
-
playSound()在哪里定义?看来不是。 -
唯一相关的代码很可能在你的
sound.js... 这个问题不能以目前的形式真正得到回答 -
另外5秒的延迟可能是由于加载音频文件造成的。文件有多大,你打算如何播放它们(这也是 James 的要求)?
-
您检查过您的控制台吗?该代码至少有 3 个语法错误,
playSound中的额外});...,在两个文档就绪调用后缺少});... -
playSound() 在那里,但在我的问题中没有很好地复制。很抱歉。
标签: javascript