Skip to content

Overview

setup(config) is the entry point for every player instance. It is synchronous in its first pass (wiring, seeding state, emitting beforeSetup) and asynchronous in the pipeline it kicks off (which emits ready when done).

You can call setup() immediately and safely enqueue addPlugin() and queue() calls before ready, they are buffered and applied during the right pipeline stage.

Signature

TypeScript
player.setup(config: BasePlayerConfig): this

Returns the player instance for chaining.

Throws: core:lifecycle/already-setup if called twice without dispose() first; core:player/disposed if called after dispose().

Setup pipeline

The async pipeline fires events in this order. Each stage has a paired error event; any unhandled error rejects the ready() promise.

Stage eventError eventWhat happens
beforeSetupLast chance to add plugins before the pipeline starts
setupStartsetupStartErrorPhase to setup, container element resolved
configResolvedconfigResolvedErrorOptions normalised and validated
pluginsRegisteringpluginsRegisteringErrorQueued plugins registered in priority order
pluginsRegisteredpluginsRegisteredErrorAll plugins’ use() promises settled
streamsReadystreamsReadyErrorDefault stream factories (hls, native) registered
authReadyauthReadyErrorAuth config resolved; token factory called once to warm
playlistReadyplaylistResolveErrorconfig.playlist URL fetched (if string) or items queued (if array)
mediaReadymediaReadyErrorFirst item loaded into backend (when config.playlist had items)
readyPlayer is ready to accept commands

Key config fields

The full BasePlayerConfig is documented in Key Interfaces, BasePlayerConfig. Most common fields:

FieldTypeDefaultDescription
baseUrlstringnonePrepended to relative media URLs in playlist items
logLevel'silent' | 'error' | 'warn' | 'info' | 'debug' | 'trace''info'Log verbosity
authAuthConfignoneBearer token, headers, refresh function
playlistBasePlaylistItem[] | stringnoneInitial playlist (items or URL to fetch)
storageIStorageLocalStorageBackendPluggable storage backend
platformIPlatformbrowserPlatformPlatform abstraction
exposebooleanfalseAttach instance to window.player for debugging
wakeLock'auto' | 'always' | 'never''auto' (video) / 'never' (music)Screen wake-lock policy
onOffline'pause' | 'continue-buffered' | 'ignore''continue-buffered'Behaviour when network goes offline
progressIntervalMsnumber5000How often the throttled progress event fires
metricsIntervalMsnumber10000How often playback:metrics fires (0 = off)
mutationGuardsfalse | 'all' | string[]undefinedMutation advisory control
castCastConfignoneChromecast configuration

ready()

Returns a promise that resolves when the setup pipeline reaches ready, or rejects if any stage fails or dispose() is called first. Memoised, so repeated calls return the same promise.

TypeScript
const player = nmplayer('main').setup({
baseUrl: 'https://raw.githubusercontent.com/NoMercy-Entertainment/nomercy-media/master/Films',
auth: { bearerToken: () => myAuth.getToken() },
playlist: [{ id: '1', title: 'Sintel', url: '/Sintel.(2010)/Sintel.(2010).NoMercy.m3u8' }],
});

await player.ready();
await player.play();

setupState()

Coarse lifecycle readiness as a SetupState enum value.

Phase(s)Return value
idleSetupState.NOT_SETUP
setupSetupState.SETTING_UP
disposing, disposedSetupState.DISPOSED
anything elseSetupState.READY

See also