我目前正在使用coffeescript播放wav文件 我正在使用下面的这段代码来播放声音文件
I'm currently using coffeescript to play wav file I'm using this code below to play sound file
* *我的Coffeescript
audio = new Audio('error.wav'); audio.play();我将error.wav放在/app/assets/audio/error.wav
I put error.wav in /app/assets/audio/error.wav
导轨产生错误
在2014-01-28 11:08:04 +0700开始为127.0.0.1获取GET"/touchtypings/error.wav" 由TouchtypingsController#show
Started GET "/touchtypings/error.wav" for 127.0.0.1 at 2014-01-28 11:08:04 +0700 Processing by TouchtypingsController#show
我的理解是,它在运行脚本轨道时试图将error.wav解释为控制器中的路由和进程
my understanding when it run the script rails is trying to interprett error.wav as route and process in controller
我只想在用户键入错误时播放wav文件. 谢谢你的帮助
I just want to play the wav file when user has typed error. thank you for help
推荐答案您需要提供音频文件的绝对路径,而不是相对路径.相对路径生成GET /touchtypings/error.wav,这就是为什么路由器会选择它的原因.
You'll need to give an absolute path to the audio file rather than a relative one. The relative path is resulting in GET /touchtypings/error.wav, which is why it's being picked up by the router.
赞:
audio = new Audio('/error.wav'); // note the leading forward slash根据您的应用程序配置,所需的路径可能是/assets/error.wav而不是/error.wav
And depending on your app config, the path you want is probably going to be /assets/error.wav rather than /error.wav
更多推荐
在轨道上播放声音
发布评论