我制作了一个 phonegap 应用程序,当用户单击按钮时会播放声音:
<button onclick="playAudio('test.mp3')">Play Some Audio</button>
但是我希望当用户双击时声音停止,不知何故我的代码不起作用!我是 javascript 的初学者,并认为我没有将变量 = 媒体放在正确的位置。这是我的完整代码:
<body>
<h1>Playing Audio</h1>
<button onclick="playAudio('test.mp3')">Play Some Audio</button>
<script type="text/javascript" src="cordova-2.4.0.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript">
app.initialize();
var playing = false;
var media = null;
function playAudio(src) {
if (!playing) {
if (device.platform == 'Android') {
src = '/android_asset/' + src;
}
var media = new Media(src);
media.play();
playing = true;
} else {
media.stop();
playing = false;
}
}
</script>
</body>