nmplayer
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:
| Name | Type | Description |
|---|---|---|
id | string | number | Optional. 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
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
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
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
const player = nmplayer('player')
.addPlugin(DesktopUiPlugin)
.addPlugin(KeyHandlerPlugin)
.setup({ playlist: [{ url: '...' }] });
dispose
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.