开发者

Dynamically add an 'Embed' type element to a document from within XUL

开发者 https://www.devze.com 2023-02-10 07:05 出处:网络
This might sound vague, but I\'ve suffered the last 6 hours attempting to solve this \"simple\" feat:

This might sound vague, but I've suffered the last 6 hours attempting to solve this "simple" feat:

  1. I have code running within a Firefox Addon
  2. User triggers an action that requires some audio to be played back, but the catch here is - this audio is dynamic (depends in input from user), and is being fetched from a server somewhere.
  3. I choose to dynamically insert an embed element into a new tabbrowser's document with its src pointing towards the server resource, but am TOTALLY FAILLING to make this work! I failed to embed the element!

Funny thing is that it works well from no开发者_JS百科rmal javascript function scope (code within a script tag in an html document), but all fails when am using XUL.

Below is come code snippet

function loadURL(url)  
{
var razorTabBrowser = gBrowser.getBrowserForTab(gBrowser.addTab("chrome://razorextension/content/read.html"));  
razorTabBrowser.addEventListener("load", function () { 

    var soundEmbed = razorTabBrowser.contentDocument.createElement("embed");
     soundEmbed.setAttribute("src", url);
     soundEmbed.setAttribute("hidden", true);
     soundEmbed.setAttribute("autostart", true);
     soundEmbed.removed = false;

     razorTabBrowser.contentDocument.body.appendChild(soundEmbed)

    }, true);
}


As far as I know, nsISound.play works on remote URLs, as long as it's WAV format.

EDIT:

I can't remember which version of Firefox supports <html:audio> but I think you can use it without even adding it to a document.

0

精彩评论

暂无评论...
验证码 换一张
取 消