Skip to content

Instantly share code, notes, and snippets.

@nakajmg
Last active December 14, 2015 12:08
Show Gist options
  • Save nakajmg/5083722 to your computer and use it in GitHub Desktop.
Save nakajmg/5083722 to your computer and use it in GitHub Desktop.
SoundJSつかって再生と停止するだけ
<html>
<head>
<title>SoundJS test</title>
</head>
<body>
<div id="play">play</div>
<div id="stop">stop</div>
<div id="state" style="text-decoration: underline;color:red;">playing</div>
<script src="soundjs-0.4.0.min.js"></script>
<script src="sound.js"></script>"
</body>
</html>
function init(){
if(!createjs.Sound.initializeDefaultPlugins()){
console.log("error");
return false;
}
createjs.Sound.registerPlugins([createjs.HTMLAudioPlugin]);
createjs.Sound.addEventListener('loadComplete',handleLoadComplete);
createjs.Sound.registerSound("./sample.ogg","sample");
}
function handleLoadComplete(event){
var instance = createjs.Sound.play("sample");
document.getElementById('play').addEventListener('click',function(){
instance.play();
changeStateText('playing');
});
document.getElementById('stop').addEventListener('click',function(){
instance.stop();
changeStateText('stop');
});
instance.onComplete = function(){
changeStateText('play end');
}
}
function changeStateText(state){
document.getElementById('state').innerText = state;
}
window.onload = function(){
init();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment