HTML 5 audio element doesn't loop in Rails

I am trying to use this javascript to create an audio element:

music.js:

myAudio = new Audio('/assets/drumloop.mp3'); myAudio.loop = true; myAudio.play(); 

When I include this as a script in a simple html file and open the html file in Safari 5.1, it becomes accurate. When I enable this javascript from my Rails application running on a local rails server, the sound is playing but not working.

I tried using the callback in the "finished" event to set the time to zero and play again (as suggested here , but that won't work either.

Is it possible that the rails do not send enough information to the http header?

+8
javascript html5 ruby-on-rails audio
source share
2 answers

I often run into the same problem. I did not find a real solution, but came up with "good enough during development."

I ended up uploading my audio files to another server and referencing them from my rails application during development if I really needed to check the loop or search.

Apache running on localhost worked fine for me. You can also use a web server. Just remember to change these paths before deployment!

Super disappointment.

+1
source share

You do not need JS for this. Try this html code:

 <audio controls="controls" loop="loop"> <source src="/assets/drumloop.mp3" type="audio/mpeg" /> </audio> 

Key loop = "loop"

0
source share

All Articles