Question

Apologies for no Fiddle; just trying to understand SoundManager 2's basics and failing miserably.

Why doesn't this work:

<script>
soundManager.setup({
  url: 'swf/',
  preferFlash: false,
  onready: function() {
    // Ready to use; soundManager.createSound() etc. can now be called.
  }
});
</script>

<script>
$(document).ready(function() {
  soundManager.createSound({
    id: 'mySound',
    url: 'audio/sound.mp3',
    autoLoad: true,
    autoPlay: true,
    volume: 50
  });
  mySound.play();
});
</script>

But this does:

<script>
soundManager.setup({
  url: 'swf/',
  preferFlash: false,
  onready: function() {
    soundManager.createSound({
      id: 'mySound',
      url: 'audio/mySound.mp3',
      autoLoad: true,
      autoPlay: true,
      volume: 50
    });
    mySound.play();
  }
});
</script>

I don't get it... at all. Does every sound have to be loaded into onready()? And if so, how is that remotely useful for 90% of use cases? I have to be missing something. The examples they provide make it seem as easy putting this anywhere in my code:

soundManager.createSound({
 id: 'mySound2',
 url: 'audio/mySound2.mp3'
});
soundManager.play('mySound2');

Yet it doesn't work. Why?

Was it helpful?

Solution

From the comments

The API properbly need to do some thing on intialize and before it is ready to run. If you call createSound before the API have finished loading there will be a error. Instead of using $(func..) as you starting point, you could try using the onready, and call the $(functio.. from inthere

I have made a non-working fiddle of what i mean: http://jsfiddle.net/YdC8j -- I have not working with soundmanager I am just guessing

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top