【问题标题】:HTML 5 audio tags not appearing in GreaseMonkeyGreaseMonkey 中没有出现 HTML 5 音频标签
【发布时间】:2010-08-30 17:02:40
【问题描述】:

我正在编写我的第一个 GM 脚本,用 HTML 5 音频标签替换 http://www.freesound.org 上的 Flash 预览,并在搜索结果中添加下载链接。我让后者工作正常,但我无法在 Firefox 3.5.9 中显示音频标签。这是我的脚本:

// ==UserScript==
// @name           FreeSound HTML 5 Preview
// @namespace      http://thewordnerd.info
// @description    Replace Flash-based sound previews on freesound.org with audio tags and add quick download links
// @include http://freesound.org/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.js
// ==/UserScript==

$(document).ready(function() {
  $("embed").remove();
  $(".samplelist").each(function(index) {
    sampleNo = $(this).find("a:first").attr("href").split("?")[1].split("=")[1];
    userName = $(this).find("a:eq(1)").html();
    title = $(this).find("a:first").html().replace(/ /g, "_");
    url = "/download/"+sampleNo+"/"+sampleNo+"_"+userName+"_"+title;
    $(this).find("script").replaceWith("<audio src='"+url+"' controls='controls' type='audio/wave'/>");
    //$(this).find("audio").removeAttr("tabindex");
    $(this).append("<a href='"+url+"'>Download</a>");
  });
});

我可以在 Firebug 中看到该元素,看起来还不错。

想到我在这里可能做错了什么?由于下载链接确实下载了请求的文件,因为它是一个波,而且我认为我已经设置了正确的类型,所以我不知道为什么它没有显示。

【问题讨论】:

    标签: firefox audio html greasemonkey


    【解决方案1】:

    它可能不是您的脚本,而是freesound.org 站点/服务器。

    当我运行您的脚本的修改版本时,所有音频控件都会出现一瞬间,然后恢复为错误显示,如下所示:

    Firefox 为我检查的文件报告 MEDIA_ERR_SRC_NOT_SUPPORTED

    将此代码保存到您的机器上,然后用 Firefox 运行它:

    <html>
    <head>
        <title>Audio File test</title>
    </head>
    <body>
    <audio id="aud1" controls="true" type="audio/ogg"
    src="http://www.freesound.org/download/7521/7521_abinadimeza_Rainfall.ogg">xxx</audio>
    
    <audio id="aud2" controls="true" type="audio/ogg"
    src="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg">xxx</audio>
    </body>
    <script type="text/javascript">
        window.addEventListener ("load", ErrorReport, false);
    
        function ErrorReport (evt)
        {
            console.log (document.getElementById ("aud1").error);
            console.log (document.getElementById ("aud2").error);
        }
    </script>
    </html>
    

    .
    您会看到来自 Mozilla 的已知良好文件可以正常工作,但来自 freesound.org 的文件不能正常工作。这可能是 Firefox 中的一个错误/限制——这两个文件在我的本地播放器上都可以正常播放。

    这是link to the Firefox bug system, to search for or report bugs

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-11-30
      • 2016-06-17
      • 2023-02-03
      • 2016-02-18
      • 1970-01-01
      相关资源
      最近更新 更多