Deezer Media Session Support for Chrome
当前为
// ==UserScript==
// @name Deezer Media Session Support
// @namespace http://tampermonkey.net/
// @description Deezer Media Session Support for Chrome
// @include http://*.deezer.com/*
// @include https://*.deezer.com/*
// @version 1.0.2
// @run-at document-idle
// @noframes
// ==/UserScript==
(function (dzPlayer, prevSongId, seekConst, noLimit){
setInterval(function(currSong){
currSong = dzPlayer.getCurrentSong();
if (currSong && currSong.SNG_ID !== prevSongId){
noLimit && (dzPlayer.radioSkipCounter=1); // unlimited skips
prevSongId = currSong.SNG_ID;
navigator.mediaSession.metadata = new MediaMetadata({
title: currSong.SNG_TITLE,
artist: currSong.ART_NAME,
album: currSong.ALB_TITLE,
artwork: ['264x264'].map(function(size){
return {'src': `https://e-cdns-images.dzcdn.net/images/cover/${currSong.ALB_PICTURE}/${size}-000000-80-0-0.jpg`,
'sizes': size,
'type': 'image/jpg'}
})
});
}
}, 500);
navigator.mediaSession.setActionHandler('previoustrack', function() {
if (!dzPlayer.isRadio() || noLimit){
dzPlayer.control.prevSong();
}
});
navigator.mediaSession.setActionHandler('nexttrack', function() {
dzPlayer.control.nextSong();
});
navigator.mediaSession.setActionHandler('play', function() {
dzPlayer.control.play();
});
navigator.mediaSession.setActionHandler('pause', function() {
dzPlayer.control.pause();
});
navigator.mediaSession.setActionHandler('seekbackward', function() {
dzPlayer.control.seek(Math.max(dzPlayer.getPosition() - seekConst, 0) / dzPlayer.getDuration());
});
navigator.mediaSession.setActionHandler('seekforward', function() {
dzPlayer.control.seek(Math.min(dzPlayer.getPosition() + seekConst, dzPlayer.getDuration()) / dzPlayer.getDuration());
});
})(dzPlayer, 0, 30, false);