Music bug - what's wrong?

I'm trying to use the following code to play music:

    ogg = new Audio();
    ogg.src = "music_fight.mp3";
    ogg.loop=true;
    ogg.load();
    ogg.play();
    set ("ogg",ogg);

The strange thing is - it works in my test program. I've put in various fake sections and can change the music from file to file. But when I put it into my large game, nothing.

I originally put it in as a function but it didn't work. I eventually just put it at the very top of all my javascripts, and still nothing. This is driving me crazy. What sort of thing might disable this in a specific squiffy file?


Further investigation shows that it seems that you need to click through a section to make the music work. So, this works...

[[start]]:

[[main]]

[[main]]:
    ogg = new Audio();
    ogg.src = "music_fight.mp3";
    ogg.loop=true;
    ogg.load();
    ogg.play();
    set ("ogg",ogg);
    
[[main]]

[[main]]:

...yet this does not.

[[start]]:

    ogg = new Audio();
    ogg.src = "music_fight.mp3";
    ogg.loop=true;
    ogg.load();
    ogg.play();
    set ("ogg",ogg);
    
[[main]]

[[main]]:

Can anyone explain this to me?


Probably the response to those 'crazy frog' popup ads a few years back. Most browsers don't allow automatic audio playback anymore, it has to be triggered by the user clicking something within the page.


Makes sense. To get around it, I had to add a forward page that you need to click by. A little annoying but not insurmountable. Came up with some nice art that adds to the mood.

Thanks for the explanation.


Log in to post a reply.

Support

Forums