Jump to content

Can't seem to use wildcard to play a sound


Ninjadoodle
 Share

Recommended Posts

Hi Guys

 

I've been testing my game across different browsers and noticed that it doesn't load in Firefox. The reason being that Firefox doesn't load M4A sounds.

 

I'm a little lost as what sound format(s) I should be using for cross compatibility across browsers/devices.

 

Also, do I have to load all the different formats in my assets.js?

 

How do I play a sound inside a game so it chooses the right format for the device/browser?

 

Is the some sort of wildcard setting, so you can for example say -> play jump.* vs play jump.m4a

 

Thank you heaps for any help :)

Link to comment
Share on other sites

I'm a little lost as what sound format(s) I should be using for cross compatibility across browsers/devices.

 

For my games I have all my sounds in two formats - .ogg as the preferred type and .m4a as the fallback for when .ogg is not supported.

In my experience this has been the combination that gives best coverage of browsers & devices.

Link to comment
Share on other sites

Thank you heaps for the help guys!

 

I saved all my files as ogg and m4a, the tried using -> game.audio.playMusic('audio/themeMusic.*', false);

 

... but I can't get it working :(

 

Every time I try using the wildcard, I get this error ...

 

TypeError: undefined is not an object (evaluating 'this.sources[name].audio')

 

Any idea what the problem could be?

 

Thank you again!

Link to comment
Share on other sites

Hi guys

 

I managed to get this working by using this approach:

 

In my assets.js file, I load the sounds (m4a & ogg) and give them both the same 'tag' ...

 

game.addAudio('audio/theme.m4a', 'theme');

game.addAudio('audio/theme.ogg', 'theme');

 

then in the game I use the sounds 'tag' to play it ...

 

game.audio.playMusic('theme');

 

This works well, so I guess I don't need to use the .* wildcard. I would still be interested to know how it's used and what the correct syntax is.

 

Thank you!

Link to comment
Share on other sites

This code fragment (from panda fiddler) does the job:

game.module(    'game.main').require(    'engine.core').body(function(){        game.addAudio('sound/clear.*', 'clear');    //In the media folder there are two versions of the sound file:    //clear.m4a (web/iOS)    //clear.ogg (android devices)    //Panda chooses the right soundfile automatically as a result of the asterix        game.createScene('Main', {        backgroundColor: "#ffffff",        init: function() {            //add text            var text = new game.Text("Click canvas to play a sound", { font: '30px wallfont' });            this.stage.addChild(text);          },                  click: function(e) {             game.audio.playSound("clear", false);         }    });});
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...