Skip to content

nmplayer

TypeScript
import nmplayer from '@nomercy-entertainment/nomercy-video-player';

function nmplayer(id?: string | number): NMVideoPlayer<VideoPlaylistItem>;

The default export. Creates or retrieves a player instance bound to the DOM element with the given id attribute. If a player is already attached to id, the same instance is returned (singleton per element).

Parameters:

NameTypeDescription
idstring | numberOptional. The id attribute of the container element to mount into. A number retrieves an existing instance from the registry by index.

Returns: NMVideoPlayer<VideoPlaylistItem>, the player instance, ready to chain .addPlugin() and .setup().

Example

TypeScript
import nmplayer from '@nomercy-entertainment/nomercy-video-player';
import {
DesktopUiPlugin,
SubtitleOverlayPlugin,
} from '@nomercy-entertainment/nomercy-video-player/plugins';

const player = nmplayer('player')
.addPlugin(DesktopUiPlugin)
.addPlugin(SubtitleOverlayPlugin)
.setup({
baseUrl: 'https://raw.githubusercontent.com/NoMercy-Entertainment/nomercy-media/master/Films',
playlist: [
{
title: 'Big Buck Bunny',
url: '/Big.Buck.Bunny.(2008)/Big.Buck.Bunny.(2008).NoMercy.m3u8',
image: 'https://image.tmdb.org/t/p/original/xtdybjRRZ15mCrPOvEld305myys.jpg',
},
],
});

player.on('ready', () => {
player.item(0, { autoplay: true });
});

setup

TypeScript
player.setup(config: VideoPlayerConfig): NMVideoPlayer<T>

Initialises the player with the provided configuration. Triggers the setup lifecycle, emitting in order: setupStart → configResolved → pluginsRegistered → streamsReady → authReady → playlistReady → mediaReady → ready. Must be called after all .addPlugin() calls and before any transport methods.

Returns the same player instance for chaining.

addPlugin

TypeScript
player.addPlugin<O>(plugin: PluginCtorWithId, options?: O): NMVideoPlayer<T>

Registers a plugin class and its options. Must be called before setup(). Registration happens during the pluginsRegistering phase.

Returns the same player instance for chaining.

Chaining example

TypeScript
const player = nmplayer('player')
.addPlugin(DesktopUiPlugin)
.addPlugin(KeyHandlerPlugin)
.setup({ playlist: [{ url: '...' }] });

dispose

TypeScript
player.dispose(): void

Tears down the player: disposes all plugins, removes the DOM tree, cancels pending network requests, and releases the HLS instance. Call this when the player’s container is removed from the document.

See also