Mercurial > hg > Members > e105711
view webGL/src/sound.js @ 24:3f8305d62106 draft
final commit at Game group.
author | e105711 <yomitan.ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 19 Jul 2012 16:30:33 +0900 |
parents | df7f7eef72ef |
children |
line wrap: on
line source
var filesLoaded = 1; // prevent early gameStart. var EXT = ""; function loadSounds(){ if((new Audio("")).canPlayType("audio/ogg") != "") EXT = ".ogg"; else if((new Audio("")).canPlayType("audio/wav") != "") EXT = ".wav"; else alert("your browser does not support wav and ogg File."); audioHClose = loadAudio("sound/hclose"+EXT); audioSnare = loadAudio("sound/snare"+EXT); audioKick = loadAudio("sound/kick"+EXT); audioTomA = loadAudio("sound/toma"+EXT); audioTomB = loadAudio("sound/tomb"+EXT); audioFtom = loadAudio("sound/ftom"+EXT); audioRide = loadAudio("sound/ride"+EXT); audioCymbal = loadAudio("sound/cymbal"+EXT); isAppLoaded(); // ensure gameStart. } function dummyPlay(){ audioHClose.volume = 0; audioHClose = audioPlay(audioHClose); audioHClose.volume = 1.0; } function loadBGM(filepath){ audioBGM = new Audio(); audioBGM.src = filepath; audioBGM.volume = 0.7; } function BGMEndCheck(){ return audioBGM.ended; } function loadAudio(filepath){ audioVar = new Audio(); filesLoaded++; audioVar.addEventListener('canplaythrough', isAppLoaded, false); audioVar.src = filepath; return audioVar; } function isAppLoaded() { filesLoaded--; if (filesLoaded == 0){ gameStart(); } } function audioStop(audioFile){ if(!audioFile.ended){ audioFile.pause(); audioFile.load(); } } function audioPlay(audioFile){ audioFile.play(); return (new Audio(audioFile.src)); } function audioStart(audioFile){ audioFile.load(); audioFile.play(); }