IonDen / ion.sound

JavaScript plugin for playing sounds and music in browsers

Home Page:http://ionden.com/a/plugins/ion.sound/en.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rails setup

sacredceltic opened this issue · comments

commented

I'm trying to implement ion.sound with Rails 3.22

here is my .js.erb code:

<%-# initialise plugin for ion sound -%>
$.ionSound
sounds: [
{ name: 'caisse_enregistreuse' }
]
path: 'sounds/'
preload: true
multiplay: true
volume: 0.5
<%-# play sound -%>
$.ionSound.play("caisse_enregistreuse")

it doesn't produce any sound although I get no javascript error...

I tried to place the sounds in assets/, public/, public/sounds, assets/sounds
...to no avail

Hi, i assume the wrong path.
Open dev console F12, open network tab, check the url, check if your mp3 file is available on this url.

commented

Hi, thank you for your reply. Actually, the sound files are not yet in the HTML, because it should be triggered by the click on a button, triggering the .js.erb file containing (among other things) the code above.
I know the .js.erb file is executed, because the first part of the code, changing a visual element on the page actually works.

Hi again. I can't really say what is the problem here, i don't know Rails.
Maybe you could provide online demo of your page to look at?

commented

It's only on my local dev environment for the moment.
I found the following error message :"Uncaught (in promise) DOMException: Unable to decode audio data" and "ion.sound.min.js?body=1:2 No sources for "caisse_enregistreuse" sound :("

I provided the 3 different formats : .mp3, .aac, .ogg but when I look in the network tab of the console, I can see it is also attempting to load a .wav and a .mp4 which I didn't provide...
I tried with Chrome and Safari, with the same result.

You see, it tries to load different formats, this means it can't found the file. Please check again network tab and check file URL where. Is it correct? Try to open it manually. Or the path is wrong, or, maybe you server config does not have a permission to send this file types or something.

commented

I think I understand the mess, although I don't know how to solve it.
ionSound actually generates GET (Started GET "/app/assets/caisse_enregistreuse.mp3?1476880362641"...) on sound assets which are interpreted by Rails router as actual user routes and Rails processes them as such, attempting to trigger corresponding controllers' actions.
That's no good...

I don't know, maybe write an exception for urls with *.mp3, *.ogg etc.

commented

I found out : I have to put my sound assets in /public directory to avoid the routing problem. I placed them in /public/sounds, but now it does nothing. They don't even load, so I'm at a loss to make it work...

Now change path in script config
ср, 19 окт. 2016 г. в 18:21, sc notifications@github.com:

I found out : I have to put my sound assets in /public directory to avoid
the routing problem. I placed them in /public/sounds, but now it does
nothing. They don't even load, so I'm at a loss to make it work...


You are receiving this because you were assigned.

Reply to this email directly, view it on GitHub
#79 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAaJTYi1UpThl1MwuY-uQQ8U2O_fYLjfks5q1kOfgaJpZM4KZ7l6
.

Denis Ineshin
IonDen.com

commented

the ion.sound script to initialise the plugin has now :
path: '/sounds/'
which matches /public/sounds, where I placed my assets, as I was told by the Rails specialist... I get no message that it can't find the asset. I have no feedback at all...

commented

OK I finally found out after a lot of fiddling. It all comes down to my lack of skill making a difference between javascript and coffeescript.
So, for other noobs like me, here is the way to implement it with Rails:

in your <controller_name>.js.coffee

initialise plugin for ion sound

$ -> $.ionSound
sounds: [
{ name: 'metal_plate' }
]
path: '/sounds/'
preload: true
multiplay: true
volume: 0.2

in your .js.erb file:

ion.sound.play("metal_plate")

Note the differences between the 2 notations ($ -> $. / ionSound and ion.sound/"" and '') and the tabulations. If any tabulation is missing, or if any of this is missing. It just won't work.

Thank you for your help IonDen!

Np, nice that you figured it out.