views:

35

answers:

1

I'm working on my first GM script, to replace the Flash previews on http://www.freesound.org with HTML 5 audio tags, and to add a download link to search results. I have the latter working fine, but I can't get the audio tag to display in Firefox 3.5.9. Here's my script:

// ==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>");
  });
});

I can see the element in Firebug and it seems just fine.

Thoughts on what I might be doing wrong here? Since the download link does download the requested file, since it's a wave and since I think I've set the correct type, I'm at a loss as to why this isn't displaying.

A: 

It may not be your script so much as the freesound.org site/server.

When I run a modified version of your script, the audio controls all appear for a split second before reverting to the error display, like so:
alt text

Firefox reports MEDIA_ERR_SRC_NOT_SUPPORTED for the files I checked.

Save this code to your machine and then run it with 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"&gt;xxx&lt;/audio&gt;

<audio id="aud2" controls="true" type="audio/ogg"
src="http://developer.mozilla.org/@api/deki/files/2926/=AudioTest_(1).ogg"&gt;xxx&lt;/audio&gt;
</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>

.
You'll see that the known good file, from Mozilla, works correctly but the one from freesound.org does not. This may be a bug/limitation in Firefox -- both files play fine on my local player.

Here is a link to the Firefox bug system, to search for or report bugs.

Brock Adams