如何修改代码以在单独的按钮上添加第二个声音?

时间:2018-07-20 19:29:27

标签: javascript html html5 button

下面是我的代码,我只是在学习编码,只是想知道我需要在代码中进行哪些细微更改,以创建另一个与第一个按钮分开的声音的按钮。

<html>
<head>
<meta name="viewport" content="width=device-width">
<script src='file:///android_asset/app.js'></script>
</head>

<script>
var player;

function OnStart() {
    app.MakeFolder(app.GetAppPath() + "/Snd")
    app.CopyFile("/Sys/Snd/Poing.ogg", app.GetAppPath()+"/Snd/Poing.ogg");

    player = new Audio
    player.onended = player_OnComplete;
    player.src = "Snd/Poing.ogg";
    player.type = "audio/ogg";
}

function btnToggle_OnTouch() {
    switch(btnToggle.value) {
        case "Play":
        case "Resume":
            if(player.paused) {
                player.play();
                btnToggle.value = "Pause";
            }
        break;

        case "Pause":
            if(!player.paused) {
                player.pause();
                btnToggle.value = "Resume";
            }
        break;
    }
 }


function player_OnComplete() {
    btnToggle.value = "Play";
}
</script>


<body onload="app.Start()" style="background-color:#ffffff;">
<input id="btnToggle" type="button" value="Play" onclick="btnToggle_OnTouch()" onended="player_OnComplete()">
</body>
</html>

0 个答案:

没有答案