在基于 Flash 的 Canvas 项目中播放声音时遇到很多问题。我在这里使用基本示例( http://createjs.com/Docs/SoundJS/classes/Sound.html )来正常工作,但我得到的只是黑屏和以下错误:
语法错误:参数列表后缺少 )
我的 JS 文件如下:
createjs.Sound.on("fileload", createjs.proxy(this.loadHandler, (this));
所以我添加了额外的 ) 但现在又出现了另一个错误:
类型错误:createjs.Sound 未定义
这是哪个:
createjs.Sound.registerPlugins([createjs.WebAudioPlugin, createjs.FlashAudioPlugin]);
这是怎么回事?为什么我不能直接播放它?
完整代码如下:
createjs.Sound.registerPlugins([createjs.WebAudioPlugin, createjs.FlashAudioPlugin]);
createjs.Sound.alternateExtensions = ["mp3"];
createjs.Sound.on("fileload", createjs.proxy(this.loadHandler, (this)));
createjs.Sound.registerSound("sounds/LaGrange.mp3", "sound");
function loadHandler(event) {
// This is fired for each sound that is registered.
var instance = createjs.Sound.play("sound"); // play using id. Could also use full source path or event.src.
instance.on("complete", createjs.proxy(this.handleComplete, this));
instance.volume = 0.5;
}
最佳答案
那就尴尬了。该示例确实有 2 个错误。第一个是缺少的“)”,您发现并更正了它。第二是FlashAudioPlugin没有完全设置。在注册插件之前,您需要添加此行来设置 FlashAudioPlugin.swf 的路径:
createjs.FlashAudioPlugin.swfPath = "../src/soundjs/flashaudio";
感谢您捕捉到这一点。我已将其修复版本推至 github 。此外,所有的demos如果您想要更多工作示例进行测试,则已经经过充分测试。
希望有帮助。
关于javascript - 无法在我的 Flash/HTML5/Canvas 项目中播放音频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29724858/