基于StackExchange的代码,我已经找到了打开wav文件的代码。 wav文件本身是一个有效的文件,因为它可以与我拥有的Python程序一起正常播放。但是javascript函数不起作用。声音文件与我的html文件位于同一文件夹中。
<div id="play_or_pause_or_exit">
<button onclick="playAudio()" type="button" id="play" style="display:inline-block;">Play table</button>
<button onclick="pauseAudio()" type="button" id="pause" style="display:inline-block;">Pause table</button>
<button onclick="cancelAudio()" type="button" id="cancel" style="display:inline-block;">Exit tables</button>
<script>
var audio;
function setupAudio(){
var audio = new Audio('plus1_071016_Alex.WAV');
}
function playAudio(){
audio.play();
}
function pauseAudio(){
audio.pause();
}
function cancelAudio(){
audio.pause();
sound.currentTime = 0;
}
</script>
</body>
</html>
任何帮助都将不胜感激。
答案 0 :(得分:1)
你没有入口点...什么叫你的setupAudio()?这将帮助您启动并运行
<html>
<head>
<title>Test</title>
</head>
<body>
<script>
// var audio = new Audio("plus1_071016_Alex.WAV");
// var audio = new Audio("http://glpjt.s3.amazonaws.com/so/av/a12.mp3");
var audio = new Audio("https://s3.amazonaws.com/audio-experiments/examples/elon_mono.wav");
function playAudio() {
audio.play();
}
function pauseAudio() {
audio.pause();
}
function cancelAudio() {
audio.pause();
audio.currentTime = 0;
}
</script>
<body>
<div id="play_or_pause_or_exit">
<button onclick="playAudio()" type="button" id="play" style="display:inline-block;">Play/Resume table</button>
<button onclick="pauseAudio()" type="button" id="pause" style="display:inline-block;">Pause table</button>
<button onclick="cancelAudio()" type="button" id="cancel" style="display:inline-block;">Exit tables</button>
</body>
</html>
&#13;