我正在使用 React 和 Electron 编写一个音乐播放器,并希望添加音频元数据,以便获得 MPRIS 支持。所以我做了一些搜索并发现媒体会话API是我所需要的。
为了测试它,我将上述链接包含的示例代码中的代码复制到我的项目中的函数中。
navigator.mediaSession.metadata = new MediaMetadata({
title: 'Unforgettable',
artist: 'Nat King Cole',
album: 'The Ultimate Collection (Remastered)',
artwork: [
{ src: 'https://dummyimage.com/96x96', sizes: '96x96', type: 'image/png' },
{ src: 'https://dummyimage.com/128x128', sizes: '128x128', type: 'image/png' },
{ src: 'https://dummyimage.com/192x192', sizes: '192x192', type: 'image/png' },
{ src: 'https://dummyimage.com/256x256', sizes: '256x256', type: 'image/png' },
{ src: 'https://dummyimage.com/384x384', sizes: '384x384', type: 'image/png' },
{ src: 'https://dummyimage.com/512x512', sizes: '512x512', type: 'image/png' },
]
});
我将其放入一个函数中,当播放下一首歌曲时,组件将调用该函数。但是,我收到了如下错误:
Failed to compile.
./src/components/FM/Cover/index.jsx
Line 112: 'MediaMetadata' is not defined no-undef
Search for the keywords to learn more about each error.
Why?