onemaxone Posted April 23, 2017 Share Posted April 23, 2017 Hi, I have just replaced the minified Phaser js with the latest version (2.7.7) in my phaser app and my audio in my app has stopped working. The rest of the app still works well. The code to load the audio is pretty simple - I first load the audio and then add the audio assigning it to an array. game.load.audio('sound.correct', 'assets/sound.general/sound.correct.mp3'); general_sounds[0] = game.add.audio('sound.correct'); When I come to playing the audio I just use: general_sounds[0].play() Which worked in 2.0.1 but now I get the error I get is as per below: phaser.min.js:3 Uncaught TypeError: Cannot read property 'createBufferSource' of null at c.Sound.play (phaser.min.js:3) at <anonymous>:1:19 play @ phaser.min.js:3 (anonymous) @ VM1834:1 What's more odd is that when I run the above 3 commands in the console the sound plays. Does anyone know what is going on? Link to comment Share on other sites More sharing options...
RalphWiggum Posted April 23, 2017 Share Posted April 23, 2017 could you try using phaser.js instead of phaser.min.js ? and then paste the error output with line numbers ? Link to comment Share on other sites More sharing options...
onemaxone Posted April 24, 2017 Author Share Posted April 24, 2017 Hey RalphWiggum, below is a simplified version of the code that I am using - with the below, general_sounds[1] plays but 0 and 2 don't. If I put the loadGeneralSound(); call in create(){} instead of preload(){} I get the error below the code. I can try to switch out the phaser js as you mention and paste the error in also. <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title>Snap - it's kids play!</title> <script type="text/javascript" src="js/phaser.min.js"></script> <style type="text/css"> body { margin: 0; } </style> </head> <body> <script type="text/javascript"> var game = new Phaser.Game(800, 600, Phaser.AUTO, '', { preload: preload, create: create}); var general_sounds = []; function preload() { // load general sounds loadGeneralSound(); } function create() { general_sounds[0].play(); general_sounds[1].play(); general_sounds[2].play(); } // loads general sounds that are not object specific function loadGeneralSound() { game.load.audio('sound.correct', 'assets/sound.general/sound.correct.mp3'); game.load.audio('sound.incorrect', 'assets/sound.general/sound.incorrect.mp3'); game.load.audio('voice.correct', 'assets/sound.general/sound.well_done.m4a'); general_sounds[0] = game.add.audio('sound.correct'); general_sounds[1] = game.add.audio('sound.incorrect'); general_sounds[2] = game.add.audio('voice.correct'); } </script> </body> </html> Errors if I put the loadGeneralSound(); call in create(){} instead of preload(){}: Phaser CE v2.7.7 | Pixi.js | WebGL | WebAudio http://phaser.io ♥♥♥ phaser.min.js:3 Phaser.Cache.isSoundDecoded: Key "sound.correct" not found in Cache. getItem @ phaser.min.js:3 isSoundDecoded @ phaser.min.js:3 play @ phaser.min.js:3 create @ snap.html:27 loadComplete @ phaser.min.js:3 preUpdate @ phaser.min.js:3 updateLogic @ phaser.min.js:3 update @ phaser.min.js:3 updateRAF @ phaser.min.js:3 window.requestAnimationFrame.forceSetTimeOut._onLoop @ phaser.min.js:3 phaser.min.js:3 Phaser.Cache.getSound: Key "sound.correct" not found in Cache. getItem @ phaser.min.js:3 getSound @ phaser.min.js:3 play @ phaser.min.js:3 create @ snap.html:27 loadComplete @ phaser.min.js:3 preUpdate @ phaser.min.js:3 updateLogic @ phaser.min.js:3 update @ phaser.min.js:3 updateRAF @ phaser.min.js:3 window.requestAnimationFrame.forceSetTimeOut._onLoop @ phaser.min.js:3 phaser.min.js:3 Phaser.Cache.isSoundDecoded: Key "sound.incorrect" not found in Cache. getItem @ phaser.min.js:3 isSoundDecoded @ phaser.min.js:3 play @ phaser.min.js:3 create @ snap.html:28 loadComplete @ phaser.min.js:3 preUpdate @ phaser.min.js:3 updateLogic @ phaser.min.js:3 update @ phaser.min.js:3 updateRAF @ phaser.min.js:3 window.requestAnimationFrame.forceSetTimeOut._onLoop @ phaser.min.js:3 phaser.min.js:3 Phaser.Cache.getSound: Key "sound.incorrect" not found in Cache. getItem @ phaser.min.js:3 getSound @ phaser.min.js:3 play @ phaser.min.js:3 create @ snap.html:28 loadComplete @ phaser.min.js:3 preUpdate @ phaser.min.js:3 updateLogic @ phaser.min.js:3 update @ phaser.min.js:3 updateRAF @ phaser.min.js:3 window.requestAnimationFrame.forceSetTimeOut._onLoop @ phaser.min.js:3 phaser.min.js:3 Phaser.Cache.isSoundDecoded: Key "voice.correct" not found in Cache. getItem @ phaser.min.js:3 isSoundDecoded @ phaser.min.js:3 play @ phaser.min.js:3 create @ snap.html:29 loadComplete @ phaser.min.js:3 preUpdate @ phaser.min.js:3 updateLogic @ phaser.min.js:3 update @ phaser.min.js:3 updateRAF @ phaser.min.js:3 window.requestAnimationFrame.forceSetTimeOut._onLoop @ phaser.min.js:3 phaser.min.js:3 Phaser.Cache.getSound: Key "voice.correct" not found in Cache. getItem @ phaser.min.js:3 getSound @ phaser.min.js:3 play @ phaser.min.js:3 create @ snap.html:29 loadComplete @ phaser.min.js:3 preUpdate @ phaser.min.js:3 updateLogic @ phaser.min.js:3 update @ phaser.min.js:3 updateRAF @ phaser.min.js:3 window.requestAnimationFrame.forceSetTimeOut._onLoop @ phaser.min.js:3 Link to comment Share on other sites More sharing options...
RalphWiggum Posted April 24, 2017 Share Posted April 24, 2017 I moved the add audio array stuff into create but kept the load audio in the preload and I got it to work see code here - https://pastebin.com/sFbF2JgR of course I had to use different sound files I picked some from the phaser example folder I wonder if the problem could be this that I saw and made boldhttps://photonstorm.github.io/phaser-ce/Phaser.State.html preload() preload is called first. Normally you'd use this to load your game assets (or those needed for the current State)You shouldn't create any objects in this method that require assets that you're also loading in this method, as they won't yet be available. Link to comment Share on other sites More sharing options...
Recommended Posts