Reputation: 988
I have a webpage index.php
which contains a link to sound.php
. On sound.php
, sound is played using SoundJS.
When I navigate from sound.php
to index.php
, Google Chrome usually (but not always) displays an error message ("Aw, Snap!"):
https://support.google.com/chrome/answer/95669?hl=en
I'm using Chrome 40 for Mac OS. It doesn't matter whether I use a link or the browser's back button.
Here's my code:
sound.php
calls a JS function that's using SoundJS:
<script type="text/javascript">
var int = [0, 7];
prepareAudio();
</script>
As soon as I delete this code, the browser doesn't crash anymore.
prepareAudio() is in an external file:
function prepareAudio() {
// Try WebAudio or HTMLAudio
createjs.Sound.initializeDefaultPlugins();
// Try flash otherwise
if (!createjs.Sound.isReady()) {
// Flash plug-in is not default
createjs.FlashPlugin.swfPath = "../audio/";
// Enable flash support
$.getScript("../../js/flashplugin-0.6.0.min.js");
// Prefer WebAudio over HTMLAudio. Prefer HTMLAudio over Flash.
createjs.Sound.registerPlugins([createjs.WebAudioPlugin, createjs.HTMLAudioPlugin, createjs.FlashPlugin]);
}
// Get audio files
var audioPath = "../audio/";
var manifest = [];
for (var i = 0; i< audioFiles.length; i++)
manifest.push({id: audioFiles[i], src: audioPath + audioFiles[i] + ".ogg"});
// Play audio
var queue = new createjs.LoadQueue();
createjs.Sound.alternateExtensions = ["mp3"];
queue.installPlugin(createjs.Sound);
queue.addEventListener("complete", function() {playTask(int);});
queue.loadManifest(manifest);
createjs.Sound.registerSounds(manifest, audioPath);
}
There's some more code involved. I play sounds using
createjs.Sound.play(mySound);
Audio playback is fine in Chrome and other browsers.
Upvotes: 1
Views: 1313
Reputation: 647
It appears to be fixed in new Chrome release 40.0.2214.115, but a workaround done by OJay here helped me to overcome this issue prior to this Chrome fix :
var isChrome40 = navigator && navigator.userAgent &&
navigator.userAgent.match("40.0.2214.111");
if (isChrome40) {
createjs.Sound.registerPlugins([createjs.HTMLAudioPlugin]);
}`
Upvotes: 0
Reputation: 988
As gskinner pointed out, the problem can be reproduced on other websites. It can also be reproduced on pages that only use a single audio resource.
The problem is specific to Chrome 40 (or at least very recent versions of Chrome). It is not specific to certain versions of SoundJS.
Using another browser seems to be the only solution.
Upvotes: 3
Reputation:
When a page loses focus, chrome reduces the amount of available resources to your page. Usually, this isn't that big of a deal, but when you are dealing with sounds, it can cause some really odd behavior.
You can detect when a page loses focus with the window.onblur
. You should try reducing the resources your javascript is using when the window loses focus. If that works, you found your culprit. If not, you should probably submit a bug report to google.
Upvotes: 0