Events
Subscribe to player lifecycle events and react to playback milestones.
Last updated
import type { NuclearPluginAPI } from '@nuclearplayer/plugin-sdk';
export default {
onEnable(api: NuclearPluginAPI) {
const unsubscribe = api.Events.on('trackFinished', (track) => {
api.Logger.info(`Finished: ${track.title}`);
});
// Return a cleanup function for onDisable
return () => {
unsubscribe();
};
},
};// Subscriptions
api.Events.on<E extends keyof PluginEventMap>(
event: E,
listener: (payload: PluginEventMap[E]) => void | Promise<void>
): () => voidtype PluginEventMap = {
trackStarted: Track; // from @nuclearplayer/model
trackFinished: Track;
};
type PluginEventListener<E extends keyof PluginEventMap> = (
payload: PluginEventMap[E],
) => void | Promise<void>;type Track = {
title: string;
artists: ArtistCredit[];
album?: AlbumRef;
durationMs?: number;
trackNumber?: number;
disc?: string;
artwork?: ArtworkSet;
tags?: string[];
source: ProviderRef;
};