firefox插件SDK不使用新音频播放音频

2024-03-31

我正在开发一个 Firefox 扩展,我希望它在事件发生时播放通知声音。然而,尽管遵循了从 Firefox 扩展的数据目录播放音频 https://stackoverflow.com/questions/16449813/play-audio-from-firefox-extensions-data-directory,声音不播放。它存储在我的数据目录中。这是我的代码:

var pageworker = require ("sdk/page-worker");
let { setTimeout } = require("sdk/timers"); //setTimeout is not enabled by default in ff extensions

function playSound(sound){
  console.log("playing sound: "+sound);
  var soundPlayer = pageworker.Page({
    contentURL: data.url("blank.html"),
    contentScript: "new Audio('notification-1.mp3').play();console.log('the audio did run')",//This is where it should play, but it doesn't, even if I remove the console.log
    //The script does work if I type it into the javascript console, but replace the file name with a file:/// URL
  });
  setTimeout(function(){soundPlayer.destroy();},5000);//destroy the sound player after 5 seconds
}

但尽管两者控制台日志被调用,没有任何音频播放。 这在 XPI 中和使用 cfx 时都是如此。


正如评论中所述,尝试在contentScript string:

"new Audio("+data.url("notification-1.mp3")+").play();"
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

firefox插件SDK不使用新音频播放音频 的相关文章

随机推荐