为什么我不能将自己录制的声音放在我的网站中...
file:///C:/Users/smilburn/Desktop/bug.wav
我试过这个...
<li data-word="bug" data-audio="file:///C:/Users/smilburn/Desktop/bug.wav" data-pic="http://pixabay.com/static/uploads/photo/2012/04/16/12/17/black-35741_640.png"></li>
为什么我不能将自己录制的声音放在我的网站中...
file:///C:/Users/smilburn/Desktop/bug.wav
我试过这个...
<li data-word="bug" data-audio="file:///C:/Users/smilburn/Desktop/bug.wav" data-pic="http://pixabay.com/static/uploads/photo/2012/04/16/12/17/black-35741_640.png"></li>
您可以使用 HTML5 音频元素播放声音文件:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function playSound(urlOfSoundfile) {
document.getElementById("audioPlay").src=urlOfSoundfile;
document.getElementById("audioPlay").autoplay="autoplay";
}
</script>
</head>
<body>
<ul>
<li onclick="playSound('http://www.wav-sounds.com/various/beep.wav')">Click here to play sound from www</li>
<li onclick="playSound('file:///C:/Users/smilburn/Desktop/bug.wav')">Click here to play sound from local file</li>
</ul>
<audio id="audioPlay">
</audio>
</body>
</html>
到目前为止,并非每个浏览器都支持每种声音文件格式,因此要符合跨浏览器的要求,您应该提供不止一种格式的声音文件。
您需要在某处托管文件。源不能来自您的本地驱动器。如果您可以完全控制您的网站,只需将文件托管在您自己的服务器上即可。
编辑:更详细地说,您当前尝试做的是让您的网络服务器在网络服务器上不存在的目录中找到一个文件。您将其指向位于本地驱动器(您的计算机)上的文件。C:/ 在您的网络服务器上不存在。您需要将文件放在网络服务器本地的目录中,而不是您自己的计算机中。您可以使用第三方托管网站或自己托管。
如果您想自己托管,请访问您的网络服务器并专门为声音文件创建一个文件夹
(示例)文件:/yourwebsite/res/sounds/bug.wav
尝试查找HTML5 音频,以便了解您应该如何做。
一种方法(取自w3schools 网站)是包含 Yahoo! 媒体播放器:
<a href="song.mp3">Play Song</a>
<script type="text/javascript" src="http://mediaplayer.yahoo.com/js">
</script>
见演示:http ://www.w3schools.com/html/tryit.asp?filename=tryhtml_audio_yahoo