Playing sound in rails

ぐ巨炮叔叔 提交于 2019-12-24 06:51:19

问题


I'm currently using coffeescript to play wav file
I'm using this code below to play sound file

**my Coffeescript

audio = new Audio('error.wav');
audio.play();

I put error.wav in /app/assets/audio/error.wav

rails generate an error

Started GET "/touchtypings/error.wav" for 127.0.0.1 at 2014-01-28 11:08:04 +0700 Processing by TouchtypingsController#show

my understanding when it run the script rails is trying to interprett error.wav as route and process in controller

I just want to play the wav file when user has typed error.
thank you for help


回答1:


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.

Like this:

audio = new Audio('/error.wav'); // note the leading forward slash

And depending on your app config, the path you want is probably going to be /assets/error.wav rather than /error.wav



来源:https://stackoverflow.com/questions/21397382/playing-sound-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!