[英]Javascript, Variable is not accesible by function
I made an phonegap application that plays an sound when the user clicks on the button: 我制作了一个phonegap应用程序,该应用程序在用户单击按钮时播放声音:
<button onclick="playAudio('test.mp3')">Play Some Audio</button>
But i want that the sound stops when the user makes an doubleclick, somehow my code dont works! 但是我希望当用户双击时声音停止,以某种方式我的代码不起作用! Im an beginner in javascript, and think the i didnt put the variable = media in the right position.
我是javascript的初学者,并认为我没有将变量= media放在正确的位置。 Here is my full code:
这是我的完整代码:
<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>
Change the following line 更改以下行
var media = new Media(src);
to 至
media = new Media(src);
Now i found the problem, you cannot use 现在我发现了问题,您不能使用
media = new Media (src)
instead i had tu use 相反,我有涂用
my_Media = new Media (src)
There is an interreference with the word media! 媒体一词引起了共鸣! But what @Alexandre said was absolutley correct, and that brougt me to the final result!
但是@Alexandre说的是绝对正确的,这使我对最终结果感到震惊! Thanks
谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.