2010-08-29 52 views
0

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

// ==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中的元素,它似乎很好。

有关我在这里可能会做错的想法?由于下载链接确实下载了所需的文件,因为这是一个浪潮,因为我认为我已经设置了正确的类型,所以我不知道为什么这不显示。

回答

0

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

当我运行脚本的修改版本,音频控制所有出现的一瞬间恢复到错误显示,像这样前:
alt text

火狐报告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