Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rails setup #79

Open
sacredceltic opened this issue Oct 18, 2016 · 12 comments
Open

Rails setup #79

sacredceltic opened this issue Oct 18, 2016 · 12 comments
Assignees
Labels

Comments

@sacredceltic
Copy link

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

@IonDen
Copy link
Owner

IonDen commented Oct 19, 2016

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.

@IonDen IonDen self-assigned this Oct 19, 2016
@sacredceltic
Copy link
Author

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.

@IonDen
Copy link
Owner

IonDen commented Oct 19, 2016

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?

@sacredceltic
Copy link
Author

sacredceltic commented Oct 19, 2016

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.

@IonDen
Copy link
Owner

IonDen commented Oct 19, 2016

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.

@sacredceltic
Copy link
Author

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...

@IonDen
Copy link
Owner

IonDen commented Oct 19, 2016

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

@sacredceltic
Copy link
Author

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...

@IonDen
Copy link
Owner

IonDen commented Oct 19, 2016

Now change path in script config
ср, 19 окт. 2016 г. в 18:21, sc [email protected]:

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

@sacredceltic
Copy link
Author

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...

@sacredceltic
Copy link
Author

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!

@IonDen
Copy link
Owner

IonDen commented Oct 19, 2016

Np, nice that you figured it out.

@IonDen IonDen changed the title Doesn't work on Rails Rails setup Oct 19, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants