javascript - 有没有办法在网络推送通知(Service Worker)中播放自定义通知声音?
问题描述
我查看了很多资源,但找不到积极的结果。我想在收到推送通知时播放一些声音。
self.addEventListener("push", (e) => {
const data = e.data.json();
// console.log("Push Recieved...");
self.registration.showNotification(data.title, {
body: data.message,
icon: data?.icon,
image: data?.media,
url: data?.url,
data: { url: data?.url },
vibrate: [
100, 30, 100, 30, 100, 30, 200, 30, 200, 30, 200, 30, 100, 30, 100, 30,
100,
],
});
const playSound = new Audio(
"https://notificationsounds.com/storage/sounds/file-b8_discreet-song.mp3"
);
playSound.play();
alert("NEW ORDER RECEIVED");
navigator.vibrate([
100, 30, 100, 30, 100, 30, 200, 30, 200, 30, 200, 30, 100, 30, 100, 30, 100,
]);
});
我也试过这种方式。但发现一个错误,说音频不是函数。
解决方案
推荐阅读
- sage - 有没有办法在 Sage 中显示近似值?
- python - 为什么Sconstruct中有一些python语句没有执行?
- c++ - 破坏局部静态对象
- linux - 行数 - 如何排除目录和图像?
- parent-child - Cloud Spanner 子表可以与父表具有相同的主键吗?
- ffmpeg - ffmpeg sbs 3d mkv转3d烘焙成2d视频
- c# - 在数据网格视图 C# 中打印 XML 数据
- amazon-web-services - HIVE_BAD_DATA:parquet 中字段 id 的 BINARY 类型与表模式中定义的 int 类型不兼容
- gitlab - 如何从 Redmine 创建 Gitlab 问题
- python - 相等的更少和更大的列表python