Skip to content

Instantly share code, notes, and snippets.

@kuu
Created February 18, 2014 09:42
Show Gist options
  • Save kuu/9067678 to your computer and use it in GitHub Desktop.
Save kuu/9067678 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,minimum-scale=1.0,user-scalable=yes" />
</head>
<body>
<button id="loadBtn">Load</button>
<button id="playBtn">Play</button>
<button id="Up">Up</button>
<button id="Down">Down</button>
<script>
document.addEventListener("DOMContentLoaded", function() {
var tLoadButton = document.getElementById('loadBtn');
var tPlayButton = document.getElementById('playBtn');
var tUpButton = document.getElementById('Up');
var tDownButton = document.getElementById('Down');
var tBGM = new Audio();
tLoadButton.addEventListener('click', function () {
tBGM.src = 'bgm.mp3';
tBGM.load();
}, false);
tUpButton.addEventListener('click', function () {
var tVol = tBGM.volume + 0.1;
if (tVol <= 1) {
tBGM.volume = tVol;
}
}, false);
tDownButton.addEventListener('click', function () {
var tVol = tBGM.volume - 0.1;
if (tVol >= 0) {
tBGM.volume = tVol;
}
}, false);
tBGM.addEventListener('loadeddata', function () {
tPlayButton.addEventListener('click', function () {
tBGM.play();
}, false);
}, false);
}, false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment