Soundmanager 2(http://www.schillmania.com/projects/soundmanager2/doc/download/ ) is not working in my ruby on rails application.
Only If i add ?assets_debug=1 it works I tried all the sm .js files and none of them work restarting every time the app.
the error:
soundManager is not defined
[Break On This Error]
soundManager.setup({
and in the JS code from inside firebug:
<script>
//<![CDATA[
soundManager.setup({
url: '/assets/',
debugMode: false,
onready: function() {
var mySound = soundManager.createSound({
id: 'aSound',
url: '/assets/start.mp3',
onload: function() { console.log('sound loaded!', this); }
});
mySound.play();
},
ontimeout: function() {
}
});
//]]>
</script>
Anyone an idea why this happens?
Chances are you have two versions of the js -- the raw source files, and the compiled ones (minified, concatenated, etc.) created for use by Rails 3 asset pipeline.
Sometimes subtle bugs in JS will cause the compilation process to generate invalid code (for example, maybe if a file doesn't end with a newline and another one is tacked on). When you run with assets_debug=1
, you tell Rails to use the raw source files which are not affected.
It's a challenge to debug this -- whether in Firebug or Chrome debuggers the minified code is at best hard to read. But it could give you a clue.
Another possible cause is an unresolved dependency on jQuery version differences between Rails default and the one used by soundmanager. You might want to check to see what versions of jQuery are in play. The error you report doesn't suggest this as a cause, however.
Finally, make sure any actual dependencies are met in the app/assets/javascripts/application.js
file, perhaps by changing the order in which items are specified before or after these lines, which are not actually comments :-)
//= require jquery
//= require jquery_ujs