views:

98

answers:

2

I would like to create a simple add-on that would play a different MP3 recording every time the user double clicks a word in a webpage he is visiting and selects a special option from the context menu.

The MP3 files are located on a remote server. Normally I would use JavaScript+Flash to play the MP3 file. In a Firefox add-on, however, I'm unable to load external scripts for some reason (playing the sound works fine if it's the webpage itself that loads the scripts, but of course I need it to work with every website and not just the ones that include the script).

So what's the easiest way to play a remote MP3 file in a Firefox add-on using JavaScript?

+3  A: 

This may not entirely solve your question, as I don't BELIEVE it plays MP3s, but I'm not certain.

Firefox has nsISound, which I KNOW can play remote WAV files, as I've tested and proved it.

You may want to test it for yourself and see if it leads you a little closer!

var ios = Components.classes['@mozilla.org/network/io-service;1'].getService(Components.interfaces.nsIIOService);
var sound = ios.newURI("http://www.yoursite.com/snds/haha.wav", null, null); 
var player = Components.classes["@mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound);

player.play(sound);

Good luck, I hope this at least gets you close!

Alex
A: 

See http://www.mozdev.org/pipermail/project_owners/2008-February/011041.html

=> nsISound

You can NOT play remote files from XUL, that is a security restriction. You could load a website that plays the sound as workaround.

FrankJK
How can I play the sound from a website I load in the plugin? I run into strange issues with loading remote scripts. For example, I have a website that loads some JS scripts and plays a sound. I open it in a plugin. But for some reason it only works when I first open the site in the browser and then open the plugin from this website. Then SoundManager 2 (the script I use to play sounds) doesn't seem to work when I load the plugin from a different website, which doesn't inlude the necessary <script> tags.
pako
Of course the plugin itself always refers to the remote scripts which support playing sound, but the <script> tags included in the plugin HTML code seem to get ignored. Is it another security restriction? It seems like the plugin is unable to load remote *.js files from website A while I'm on a website B.
pako
>It seems like the plugin is unable to load remote *.js files from website A while I'm on a website B => That sounds again like a XUL security restriction to me.
FrankJK
You can NOT play remote files from XUL, that is a security restriction. You could load a website that plays the sound as workaround. --- This statement is incorrect, see my answer. You CAN play remote files in XUL, I have tested it and it does work. However support for MP3 format is not there yet.
Alex