Ninjadoodle Posted October 31, 2014 Share Posted October 31, 2014 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 Quote Link to comment Share on other sites More sharing options...
Stephan Posted October 31, 2014 Share Posted October 31, 2014 Yes, you can use wildcard like you mentioned: play jump.* vs play jump.m4a Just make sure that you have all required different sound formats included in your media folder and it works fine. Quote Link to comment Share on other sites More sharing options...
alex_h Posted October 31, 2014 Share Posted October 31, 2014 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. Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted October 31, 2014 Author Share Posted October 31, 2014 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! Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted November 1, 2014 Author Share Posted November 1, 2014 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! Quote Link to comment Share on other sites More sharing options...
Stephan Posted November 1, 2014 Share Posted November 1, 2014 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); } });}); Quote Link to comment Share on other sites More sharing options...
Ninjadoodle Posted November 1, 2014 Author Share Posted November 1, 2014 Hi @Stephan Thank you! I get it now I was trying to play the sound using a wildcard. Instead, I should be loading the sods using a wildcard, then playing the sound using the tag. I will give it a go now ... Thank you! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.