Skip to content

Instantly share code, notes, and snippets.

@kuu
Created February 19, 2014 01:14
Show Gist options
  • Save kuu/9084250 to your computer and use it in GitHub Desktop.
Save kuu/9084250 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 in 2sec</button>
<button id="playBtn">Play in 2sec</button>
<script>
document.addEventListener("DOMContentLoaded", function() {
var tLoadButton = document.getElementById('loadBtn');
var tPlayButton = document.getElementById('playBtn');
var tBGM = new Audio();
var tSE = new Audio();
tLoadButton.addEventListener('click', function () {
setTimeout(function () {
tBGM.src = 'bgm.mp3';
tSE.src = 'fire.wav';
tBGM.load();
tSE.load();
console.log('BGM#load');
console.log('SE#load');
}, 2000);
}, false);
tPlayButton.addEventListener('click', function () {
setTimeout(function () {
console.log('SE#play');
tSE.play();
}, 2000);
}, false);
tBGM.addEventListener('loadeddata', function () {
tBGM.currentTime = 5.5;
tBGM.play();
console.log('BGM#lodeddata+play');
}, false);
tSE.addEventListener('loadeddata', function () {
console.log('SE#lodeddata');
}, false);
}, false);
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment