[英]First Time SoundJS User, Can't Seem To Get A Sound To Play
I'm just... trying to get SoundJS to play a sound. 我只是...试图让SoundJS播放声音。 It appears that the file never load as my handleLoad function is never called.
似乎文件从未加载,因为从未调用过handleLoad函数。 Any ideas?
有任何想法吗?
var audioPath = "snd/";
var sounds = [
{ id: "mySound", src: "gaia.mp3" }
];
function init( ) {
createjs.Sound.addEventListener( "fileload", handleLoad );
createjs.Sound.registerSounds( sounds, audioPath );
}
function handleLoad( event ) {
console.log( "Hello from handleLoad" );
}
I get a "creates.Sound.registerSounds is not a function" error when init runs. 初始化运行时出现“ creates.Sound.registerSounds不是函数”错误。
Your demo should work. 您的演示应该可以正常工作。
I copied your code into a JSFiddle, and pointed it at a sound that I know exists. 我将您的代码复制到了JSFiddle中,并指出了我所知道的声音。 https://jsfiddle.net/lannymcnie/vj8rLghb/
https://jsfiddle.net/lannymcnie/vj8rLghb/
The only difference is I added the 3rd parameter because it is being loaded cross-domain 唯一的区别是我添加了第三个参数,因为它是跨域加载的
createjs.Sound.addEventListener("fileload", handleLoad, true);
Additionally, changes in Chrome mean that audio can't play without a user interaction, so once the audio is loaded, I added a document-click listener so it plays when you click the page anywhere. 此外,Chrome的更改意味着音频无法在没有用户交互的情况下播放,因此,在加载音频后,我添加了一个文档单击侦听器,以便您在任何地方单击页面时都可以播放。
Can you post the full error you get in the console? 您可以发布控制台中的完整错误吗? It is unclear if
registerSounds
is undefined, or if it doesn't exists on undefined
, which indicates that createjs.Sound
is undefined. 尚不清楚
registerSounds
是未定义的,还是在undefined
上不存在,这表明createjs.Sound
是未定义的。 Have you ensured that SoundJS is included properly? 您是否已确保正确包含SoundJS? Try putting this in the console:
尝试将其放在控制台中:
console.log(createjs.Sound);
Hope that helps! 希望有帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.