Playing a sound in a Firefox add-on

前端 未结 3 1191
旧巷少年郎
旧巷少年郎 2020-12-16 23:08

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 o

相关标签:
3条回答
  • 2020-12-16 23:21
    var window = require('sdk/window/utils').getMostRecentBrowserWindow();
    var audio = ('http://example.com/audio.mp3');
    audio.play();
    
    0 讨论(0)
  • 2020-12-16 23:29

    Here is a working code....

    var sound = Components.classes["@mozilla.org/sound;1"].createInstance(Components.interfaces.nsISound); 
    var soundUri = Components.classes['@mozilla.org/network/standard-url;1'].createInstance(Components.interfaces.nsIURI); 
    soundUri.spec = "chrome://secchat/content/RING.WAV"; 
    sound.play(soundUri);  
    
    0 讨论(0)
  • 2020-12-16 23:32

    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!

    0 讨论(0)
提交回复
热议问题