Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Playing a sound in a Firefox add-on

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?

like image 386
pako Avatar asked Aug 29 '10 20:08

pako


People also ask

How do I get Firefox to play sound?

Click the volume icon in the Windows taskbar. Click Mixer Mixer. The Volume Mixer window will appear. Make sure the slider for Mozilla Firefox is not muted or at the bottom.

How do I set audio in Firefox?

Click Settings on the home screen or open Applications > System Tools. Click Sound. Click the audio device you want to use.

Does Firefox support MP3?

Firefox also supports FLAC (Free Lossless Audio Codec) playback (. flac file type) and MP3 playback (. mp3 file type).


1 Answers

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!

like image 175
Purge Avatar answered Oct 03 '22 09:10

Purge