在轨道上播放声音

编程入门 行业动态 更新时间:2024-10-24 15:13:14
本文介绍了在轨道上播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我目前正在使用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

更多推荐

在轨道上播放声音

本文发布于:2023-07-11 12:11:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1094010.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:轨道   声音

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!