MediaSession 元数据更新事件?

发布于 2025-01-13 18:14:03 字数 397 浏览 2 评论 0原文

在浏览器中,我们有 MediaSession API。网页可以通过一些简单的代码显示正在播放的媒体:

navigator.mediaSession.metadata = new MediaMetadata({
  title: 'Some Tune',
  artist: 'Somebody',
  album: 'An Album',
});

我正在编写一个浏览器扩展。元数据更新时是否有事件或其他方式可以通知?目前,我正在使用轮询,但如果存在这样的事件或方法来监视新元数据,我宁愿以正确的方式进行操作。

In the browser, we have the MediaSession API. A web page can show what media is playing with some simple code:

navigator.mediaSession.metadata = new MediaMetadata({
  title: 'Some Tune',
  artist: 'Somebody',
  album: 'An Album',
});

I'm writing a browser extension. Is there an event or other way to be notified when the metadata is updated? Currently, I'm using polling, but I'd rather do it the right way if there is such an event or method to watch for new metadata.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

酸甜透明夹心 2025-01-20 18:14:03

也许是这样的。

const obj = {};
Object.defineProperty(obj, 'title', {
    set(newValue) {
        console.log('new value for title: ', newValue);
        this.value = newValue;
        navigator.mediaSession.metadata.title = newValue;
    }
});

obj.title = 'Some tune';

Maybe something like this.

const obj = {};
Object.defineProperty(obj, 'title', {
    set(newValue) {
        console.log('new value for title: ', newValue);
        this.value = newValue;
        navigator.mediaSession.metadata.title = newValue;
    }
});

obj.title = 'Some tune';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文