我正在使用 React 和 Electron 编写音乐播放器,并希望为音频添加元数据,以便获得 MPRIS 支持。所以我做了一些搜索,发现Media Session 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.
为什么?