SoundJS(PreloadJS)でmp3ファイルを読み込んで、音を鳴らしたいのですが、なぜか以下のコードだと、fileload
イベントが発火しません。原因がわかる方がいらっしゃいましたらご教授ください。
javaScript
1 2;(function(){ 3 4 function init() { 5 6 // preloadjsのインスタンスにsoundjsのクラスを渡す 7 var queue = new createjs.LoadQueue(true); 8 queue.installPlugin(createjs.Sound); 9 10 // ファイルをqueueに登録して、fileloadイベントでsoundjsのインスタンスを作るfunctionに渡す 11 var manifest = [ 12 {id: "sound1", src: "assets/sound.mp3"} 13 ]; 14 queue.loadManifest(manifest, true); 15 queue.addEventListener('fileload', handleFileLoad); 16 17 18 function handleFileLoad(event) { 19 20 var item = event.item; 21 var type = item.type; 22 if (createjs.LoadQueue.SOUND === type) { 23 startSound(item.id); 24 } 25 } 26 27 function startSound(soundid) { 28 // SoundJSのインスタンスを再生(idを指定) 29 var instance = createjs.Sound.createInstance(soundid); 30 instance.setVolume(0.1); 31 32 function doPlay() { 33 instance.play(); // 再生 34 } 35 36 function doStop() { 37 instance.stop(); // 停止 38 } 39 40 document.getElementById('play').addEventListener('click', doPlay); 41 document.getElementById('stop').addEventListener('click', doStop); 42 } 43 44 } 45 46 window.onload = function() { 47 init(); 48 } 49 50})(); 51
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。