ReferenceError:音频未定义 [英] ReferenceError: audio is not defined
问题描述
我正在Meteor中为客户构建音频播放器.
I'm building an audio player in Meteor for a client.
尝试创建音频对象时出现错误.我正在使用以下代码.知道为什么会这样吗?任何帮助将不胜感激.
I'm getting an error when I try to create an audio object. I'm using the following code. Any idea why this is happening? Any help would be greatly appreciated.
// Define Audio
song = new Audio('/audio/waitforme.mp3');
// Define Play
play = $('#playicon');
$(function() {
$('#playicon').on("click", function() {
e.preventDefault();
song.play();
})
});
ReferenceError: Audio is not defined
at AlannaSite.js:2:14
at AlannaSite.js:12:4
at /Users/CorrinSite/.meteor/local/build/programs/server/boot.js:242:10
at Array.forEach (native)
at Function._.each._.forEach (/Users/AriKamin/.meteor/packages/meteor- tool/.1.1.9.1sd3e7j++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/underscore/underscore.js:79:11)
at /Users/CorrinSite/.meteor/local/build/programs/server/boot.js:137:5
推荐答案
我认为这里存在误解.您拥有正确的代码,但是它在不同的上下文中运行.
I think there's a misconception here. You have the right code, but it's running in a different context.
对于Meteor,NodeJS后端也在运行您的客户端"代码.不幸的是,NodeJS不支持您正在使用的音频API,但是您的浏览器却支持.
In the case of Meteor, the NodeJS back-end is also running your 'client-side' code. NodeJS doesn't have support for the Audio API that you're using, sadly, but your browser does.
在客户端和服务器端都可以运行并运行的这段代码可能会让人有些困惑,尤其是当Meteor试图模糊那些行时,尤其是当客户端+服务器之间的界线时!
This code serving and running in both the client-side and server-side can get a bit confusing to know the lines between client + server, especially when Meteor tries to blur those lines!
我将查找Meteor的体系结构,以便您可以最佳地构建代码,以针对客户端"与后端"环境.一篇很棒的文章在这里: https://www.discovermeteor.com/blog/what-去哪里/
I would look up Meteor's architecture so you can best structure your code to target the 'client-end' vs. 'back-end' environments. A great article is here: https://www.discovermeteor.com/blog/what-goes-where/
基本上,Meteor提供了两个目录,您可以使用这些目录专门针对客户端或服务器.您可以将文件放在/client
或/server
中,它将为您处理.
Basically, Meteor provides two directories that you can use to specifically target the client or server. You can place files in /client
or /server
and it will be handled for you.
对于快速操作或在两种情况下都使用的文件,Meteor docs解释了一个称为Meteor.isClient
或Meteor.isServer
的布尔标志,您可以使用该标志将代码标记为仅在客户端/服务器上运行-side: http://docs.meteor.com/#/basic/Meteor-isClient
For something quick or for a file that is used in both contexts, the Meteor docs explains a boolean flag called Meteor.isClient
or Meteor.isServer
that you can use to mark code to be ran only on the client-side / server-side: http://docs.meteor.com/#/basic/Meteor-isClient
这篇关于ReferenceError:音频未定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!