MusicPlaylistItem
The default track shape for NMMusicPlayer. Every item in the playlist array must satisfy this interface (or a type that extends it).
import type { MusicPlaylistItem } from '@nomercy-entertainment/nomercy-music-player';
Interface
interface MusicPlaylistItem extends BasePlaylistItem {
// Required
id: string | number; // from BasePlaylistItem
name: string;
// Optional
url?: string;
cover?: string;
artist?: string;
album?: string;
lyricsUrl?: string;
duration?: number;
}
Fields
id (required)
id: string | number;
Unique identifier for the track.
Used by the player to locate items in the queue (queueRemove, queueIndexOf, current).
Must be unique within a session.
name (required)
name: string;
Track title. Displayed by MediaSessionPlugin on lock screens and system media controls.
name is required on music items, unlike the video player’s title?, this field has no optional fallback.
url
url?: string
Audio source URL. Supports:
- Direct MP3/AAC/FLAC/OGG:
/D/Derek%20Clegg/%5B2010%5D%20KJC/01%20Thaw%20You%20Out.mp3(relative tobaseUrl: 'https://raw.githubusercontent.com/NoMercy-Entertainment/nomercy-media/master/Music') - HLS playlist: same pattern,
hls.jsis loaded automatically when native HLS is unsupported - Relative URL: resolved against
baseUrlfrom config
When url is absent, the item can still be in the queue (the player skips it on natural advance and throws on an explicit load() call).
cover
cover?: string
Album art URL.
Consumed by MediaSessionPlugin (pushes to OS lock screen), CastSenderPlugin (included in MusicTrackMediaMetadata), and MusicUiPlugin (renders in the UI overlay).
artist
artist?: string
Plain artist name string. Consumers with linked-entity data join or pick the primary before passing to the player.
MediaSessionPlugin uses this field to populate the artist field in OS media controls.
album
album?: string
Plain album name string. Consumers with linked-entity data join or pick the primary before passing to the player.
MediaSessionPlugin uses this field to populate the album field in OS media controls.
lyricsUrl
lyricsUrl?: string
URL of an LRC lyrics file for this track.
LyricsPlugin reads this field when autoFetch: true (the default).
On each current event, the plugin fetches the URL and parses it through the player core’s cue parser registry.
If you need a different resolution strategy (e.g. looking up lyrics from a server API by track ID), pass a getLyricsUrl function in LyricsPlugin options instead of populating this field per item.
duration
duration?: number
Track duration in seconds.
This is a metadata-only fallback used by the player before the audio backend resolves the real duration from the file.
When loadedmetadata fires and the backend returns duration > 0, the backend value takes precedence and this field is ignored.
Use it to populate seekbars immediately on track load without waiting for the audio metadata probe to complete, especially on slow connections.
{
id: 'kjc-01',
name: 'Thaw You Out',
url: '/01%20Thaw%20You%20Out.mp3',
duration: 204, // 3:24, seekbar renders immediately
}
Custom fields
The player is generic: NMMusicPlayer<T>.
Extend MusicPlaylistItem with your own fields and pass the extended type at construction:
import nmMPlayer from '@nomercy-entertainment/nomercy-music-player';
import type { MusicPlaylistItem } from '@nomercy-entertainment/nomercy-music-player';
interface TrackItem extends MusicPlaylistItem {
catalogueId: number;
genre: string;
isrc: string;
}
const player = nmMPlayer<TrackItem>('main');
// player.item() returns TrackItem | undefined
// player.queue() returns ReadonlyArray<TrackItem>
Custom fields are accessible in all event payloads (current, crossfadeStart, trackEndingSoon) and inside plugins via this.player.item() when the plugin’s player generic includes & WithCurrentItem<YourItemType>.
Full example
const playlist: MusicPlaylistItem[] = [
{
id: 'kjc-01',
name: 'Thaw You Out',
url: '/01%20Thaw%20You%20Out.mp3',
cover: '/01%20Thaw%20You%20Out.jpg',
lyricsUrl: '/01%20Thaw%20You%20Out.lrc',
artist: 'Derek Clegg',
album: 'KJC',
duration: 204,
},
{
id: 'kjc-02',
name: 'Hope',
url: '/02%20Hope.mp3',
cover: '/02%20Hope.jpg',
lyricsUrl: '/02%20Hope.lrc',
artist: 'Derek Clegg',
album: 'KJC',
duration: 198,
},
];
See also
- Configuration,
playlistoption that accepts these items - Events,
currentevent payload includes the item - LyricsPlugin, reads
lyricsUrlon each track change - MediaSessionPlugin, reads
name,artist,album,cover