Jump to content

Audio Shenanigans: Some Play, Some Don't?


Recommended Posts

Hey everyone,

Over the past few months I've been working on a project in Phaser and I've come across a really frustrating problem. I don't think it's caused by Phaser or the code I've written, but has to do with the audio files themselves. Yet, I can't figure out what to do in order to make this work. I studied the example here to determine how to preload audio assets, create a variable linked to that asset, and then call it on demand. I should note that this example on the Phaser site works as intended. I can hear the example music play on both Firefox and Chrome.

I also studied other discussions about using audio in Phaser. I saw people warn against the use of MP3 as it's a licensed format, and recommended using OGG for Firefox with M4A as the fallback for Chrome. So; that's what I tried doing.

It's not gone well.

Only some of the M4A files play in Chrome. I can't figure out why, and I can't discern a pattern behind it. Some of the sounds I'd edited in Adobe Audition, others I'd left as-is. Regardless, they'd all been converted to M4A via iTunes. Some of the sounds I've edited will play, others won't; some of the sounds that were converted as-is will play, others won't. Chrome's dev console doesn't give any answers at all.

I've tried inspecting the properties of the M4A sounds with VLC Player to see if I can determine a certain setting is causing the issue, but as far as I can tell all the M4A files have the exact same properties.

I encounter the same issue on Firefox. when it comes to using MP3s. The same sounds that play on Chrome will play in Firefox; the same is true of the sounds that won't play. In this case, the error I receive is "The buffer passed to decodeAudioData contains invalid content which cannot be decoded successfully."

OGGs won't play at all. When I try to use those instead of MP3s, Firefox's console reports "error loading asset from URL assets." This is true even of sounds which work when using the MP3 or M4A format.

I'm pretty certain the issue lies with something about the audio files but I have no clue what's causing this. Does anyone have advice on how to fix this issue?

Link to comment
Share on other sites

The oggs not playing could be due to your http server not having the .ogg mime type registered. Regarding the .m4a sounds it could help to get all the source uncompressed audio into one folder and using Adobe Audition to configure all those files to be exactly the same format, ie all mono or stereo, all the same sample rate, bit depth, etc. Then batch convert them to .m4a using whatever means. That way you can be 100% sure they are all identical format.

Link to comment
Share on other sites

The source audio files came in several formats. .ogg, .wav, .mp3, .aiff. Only one of the .wavs and one of the .oggs worked out when converted to the file types I needed. Maybe one thing I could try is opening one of those files in Audition, copy audio data from the other sounds, then pasting and saving the resulting file as a new copy.

I wish I knew exactly what was making these sound files unusable, though. I never expected such finicky behavior from web-based audio ...

Link to comment
Share on other sites

I would recommend converting all the ones you are going to use into wavs first. Then make sure they are all the same sample rate and 16 bit. Ideally all mono or stereo too. Then that gives you a solid base from which to generate your compressed files to use in your game.

Link to comment
Share on other sites

Welp, I'm about ready to introduce my head to a brick wall.

So the first thing I tried was opening one of the sound files that works in-game, copying the audio data from the other sounds into it, and saving copies of these new sounds as WAV files. Theoretically these sounds should all have the exact same settings as the sound that works, so I reasoned. To test this I saved them all as MP3s (taking care not to save non-audio data), put them into the game's audio assets folder, and gave it a try.

No go. The same sounds that worked before still work, and the same sounds that didn't work still do not work.

The next thing I tried was following your suggestion, alex_h, by re-sampling the WAV files I created. I set them all to 44100Hz, 16-bit, Mono, saved them as MP3s, dropped them into the audio assets folder and tried again.

I got the same result. Only the sounds that worked from the start play. The others still do not.

I checked the developer console. The errors I previously received in Firefox aren't there anymore. And yet most of the sounds aren't playing. What the heck?

I've been double-checking my code, looking at when I call certain sounds that work versus certain ones that don't. to make sure there isn't something I'm overlooking. There aren't any typos or anything that I can see. So I decided to try something else; in a section of code that plays a working sound, switch out which sound is supposed to play and see what happens.

That worked. So I now know it's a coding issue after all, but I'm still clueless as to why.

EDIT: I'm an idiot. I went over the code one more time and discovered what's causing certain sounds to not play. I hadn't added a () after .play in those instances. However, I suppose there was also a problem with the audio files as well, since the errors I mentioned seeing previously have not shown up after homogenizing the sampling settings. I'll check and see whether this clears up the issues with the M4A files and then look into the server MIME settings to see if that's what's keeping me from using OGG audio.

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.

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.


  • Recently Browsing   0 members

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