I'm trying to play a WAV file from my assets folder but I keep getting errors. The audio tag looks like this:
<audio src="<%= asset_path('/audios/opening.wav') %>">
Browser not compatible
</audio>
And I use a Javascript function to play it with .play()
. When I test the function with a full path for WAV files that are actually hosted on the web, it works fine. It's just the one in my assets that's failing.
WAV Path :
.
├── app
│ ├── assets
│ │ ├── audios
│ │ │ └── opening.wav
Browser console error :
GET http://localhost:3000/audios/opening.wav net::ERR_ABORTED 404 (Not Found)
1 Uncaught (in promise) DOMException: Failed to load because no supported source was found.
Server error :
ActionController::RoutingError (No route matches [GET] "/audios/opening.wav"):
I'm positive that there must be a better way than creating routes for each individual audio asset, but I haven't found any solutions on here that have worked. I've seen similar questions about this using audio_path
but it seems that method may have been deprecated. Appreciate any advice I can get!
It turns out using audio_path
instead of asset_path
was the way to go! It wasn't working at first but worked after I added //= link_tree../audios
to the app/assets/config/manifest.js
file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.