player.onStopped.addListener(function _handleStopped() { // only once player.onStopped.removeListener(_handleStopped); lastfm.scrobble(timestamp, track) .then(() => logger.info('scrobbled')) .catch((error) => logger.info('scrobbling error:', error)); });
function clearScrobblingTimeout() { clearTimeout(scrobbleTimeout); } player.onPaused.addListener(clearScrobblingTimeout); player.onStopped.addListener(clearScrobblingTimeout); player.onPlaying.addListener(track => { if (track.duration > SCROBBLING_MIN_LENGTH) { setScrobblingTimeout(track); player.onResumed.addListener(setScrobblingTimeout); } }); if (SCROBBLING_NOW_PLAYING) { player.onPlaying.addListener(lastfm.nowPlaying); player.onResumed.addListener(lastfm.nowPlaying); } lastfm.getProfile() .then((user) => { ui.update({ user: user, scrobbling: SCROBBLING_ENABLED, nowPlaying: SCROBBLING_NOW_PLAYING }); ui.show(); });