【问题标题】:Leaving a webpage with SoundJS causes Google Chrome to crash使用 SoundJS 离开网页会导致 Google Chrome 崩溃
【发布时间】:2015-02-08 23:06:04
【问题描述】:

我有一个网页index.php,其中包含指向sound.php 的链接。在sound.php 上,使用 SoundJS 播放声音。

当我从 sound.php 导航到 index.php 时,Google Chrome 通常(但并非总是)显示错误消息(“哇,快!”): https://support.google.com/chrome/answer/95669?hl=en

我正在使用适用于 Mac OS 的 Chrome 40。不管我是使用链接还是浏览器的后退按钮。

这是我的代码:

sound.php 调用一个使用 SoundJS 的 JS 函数:

<script type="text/javascript">      
  var int = [0, 7];
  prepareAudio();  
</script>

只要我删除这段代码,浏览器就不会再崩溃了。

prepareAudio() 在外部文件中:

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);
}

涉及更多代码。我使用

播放声音
  createjs.Sound.play(mySound); 

在 Chrome 和其他浏览器中可以正常播放音频。

【问题讨论】:

  • 这听起来更像是 Chrome 处理声音设置的问题。 “哇,啪!”这样的问题是 Chrome 中的错误,并且会被认真对待,因此请在 Chromium 错误跟踪器中提交错误报告。
  • 我能够在 Chrome 40 OSX 中使用 SoundJS Audio Test Suite 持续重现这一点,方法是开始一些循环声音,然后点击返回按钮。但是重新启动 Chrome 后,我无法再重现。这向我表明它可能与记忆有关。也许 Chrome 的 WebAudio GC 有一个崩溃错误?可能值得向他们提交错误。
  • 这似乎已在 Chrome 40.0.2214.115 的最新版本中得到修复

标签: javascript google-chrome audio soundjs


【解决方案1】:

正如 gskinner 所指出的,该问题可以在其他网站上重现。它也可以在仅使用单一音频资源的页面上重现。

该问题特定于 Chrome 40(或至少是最新版本的 Chrome)。它并不特定于某些版本的 SoundJS。

使用其他浏览器似乎是唯一的解决方案。

【讨论】:

【解决方案2】:

当页面失去焦点时,chrome 会减少页面可用资源的数量。通常,这没什么大不了的,但是当您处理声音时,它可能会导致一些非常奇怪的行为。

您可以使用window.onblur 检测页面何时失去焦点。当窗口失去焦点时,您应该尝试减少 javascript 使用的资源。如果这行得通,你就找到了罪魁祸首。如果没有,您可能应该向 google 提交错误报告。

【讨论】:

  • 您是否假设两个页面同时打开?事实并非如此。所有页面都在同一窗口/选项卡中打开。因此,当我单击 index.php 的链接时,sound.php 已关闭,根本不应该使用任何资源。
【解决方案3】:

它似乎在新的 Chrome 版本 40.0.2214.115 中得到修复,但 OJay here 完成的解决方法帮助我在此 Chrome 修复之前克服了这个问题:

var isChrome40 = navigator && navigator.userAgent &&
navigator.userAgent.match("40.0.2214.111");
if (isChrome40) {
    createjs.Sound.registerPlugins([createjs.HTMLAudioPlugin]);
}`

【讨论】:

    猜你喜欢
    • 2017-12-09
    • 1970-01-01
    • 2015-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-10-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多