Skip to main content

Options

Player constructor options.

import Player from 'nplayer'
new Player({
// here
})

Description#

OptionDescription
containerThe player mounts the container element. Like mount method parameter, if mount is not imported, this parameter will be used. When the parameter is a string, the corresponding element will be found automatically.
srcVideo address, like video element src attribute.
videoProvide own video element.
videoPropsProperties of video element.
videoSourcesVideo source element array, see Getting Started
liveWhether is live mode
autoSeekTimeWhen the video is loaded successfully, jump to the point of time (this parameter will be set to 0 automatically). You can use this to allow memory to see the last time.
thumbnailPlease see Preview thumbnails
controlsPlease see Control Bar
bpControlsSet the layout of different breakpoint, see Control Bar
settingsPlease see Setting Menu
contextMenusPlease see Context menu
contextMenuToggletoggle context menu (browser default menu & nplayer context menu).
pluginsList of plugins, see Plugins
i18nCurrent player language, e.g. en,zh, etc
shortcutEnable shortcuts
seekStepOne-time fast and forward step long and will be used in shortcuts
volumeStepIncreases and decreases the volume step by step and will be used in a shortcut
themeColorTheme color, please see Custom Theme
posterBgColorPoster background color, please see Custom Theme
progressBgProgress bar background. See Custom Theme
progressDotPoints on progress bars, see Custom Theme
volumeProgressBgVolume bars background, please view Custom Theme
volumeBarWidthVolume width, see Custom Theme
loadingElCustom video loading element, see Custom Theme
openEdgeInIEWhether to automatically open Edge in Win10 IE, see IE 11 compatibility
posterPoster photo address, see Poster
posterEnableEnable Poster
posterPlayElCustom poster playback button, see Custom Theme

Default parameters#

{
shortcut: true,
seekStep: 10,
volumeStep: 0.1,
volumeBarWidth: 100,
settings: ['speed'],
contextMenus: ['loop', 'pip', 'version'],
contextMenuToggle: true,
openEdgeInIE: true,
posterEnable: true,
videoProps: {
crossorigin: 'anonymous',
preload: 'auto',
playsinline: 'true',
},
controls: [
['play', 'volume', 'time', 'spacer', 'airplay', 'settings', 'web-fullscreen', 'fullscreen'],
['progress'],
],
bpControls: {
650: [
['play', 'progress', 'time', 'web-fullscreen', 'fullscreen'],
[],
['spacer', 'airplay', 'settings'],
],
}
}
caution

Note that the control bar parameters will vary according to other parameters.If isTouch is true, it will not include volume, if live parameter is true, it will not include progress control items.

Options Signature#

interface PlayerOptions {
container?: HTMLElement | string;
video?: HTMLVideoElement;
src?: string;
videoProps?: Record<string, any>;
videoSources?: VideoSource[];
live?: boolean;
autoSeekTime?: number;
thumbnail?: ThumbnailOptions;
controls?: (ControlItem | string)[][];
bpControls?: { [key: string]: (ControlItem | string)[][] }
settings?: (SettingItem | string)[];
contextMenus?: (ContextMenuItem | string)[];
contextMenuToggle?: boolean;
plugins?: Plugin[];
i18n?: string;
shortcut?: boolean;
seekStep?: number;
volumeStep?: number;
themeColor?: string;
posterBgColor?: string;
progressBg?: string;
progressDot?: HTMLElement;
volumeProgressBg?: string;
volumeBarWidth?: number | string;
loadingEl?: HTMLElement;
openEdgeInIE?: boolean;
poster?: string;
posterEnable?: boolean;
posterPlayEl?: HTMLElement;
isTouch?: boolean;
[key: string]: any;
}
interface VideoSource {
media?: string;
sizes?: string;
src?: string;
srcset?: string;
type?: string;
}
interface ThumbnailOptions {
startSecond?: number;
gapSecond?: number;
row?: number;
col?: number;
width?: number;
height?: number;
images?: string[];
}
interface ControlItem {
el: HTMLElement;
id?: any;
tip?: string;
tooltip?: Tooltip;
mounted?: boolean;
init?: (player: Player, position: number, tooltip: Tooltip) => void;
update?: (position: number) => void;
hide?: () => void;
isSupport?: (player: Player) => boolean;
dispose?: () => void;
[key: string]: any;
}
interface SettingItem<T = any> {
id?: string;
html?: string;
type?: 'switch' | 'select';
checked?: boolean;
options?: SettingItemOption<T>[];
value?: T;
init?: (player: Player, item: SettingItem) => void;
change?: (value: T, player: Player, item: SettingItem) => void;
_switch?: Switch;
_selectedEl?: HTMLElement;
_optionEls?: HTMLElement[];
_optionEl?: HTMLElement;
[key: string]: any;
}
interface ContextMenuItem {
id?: string;
html?: string;
disabled?: boolean;
invisible?: boolean;
checked?: boolean;
init?: (player: Player, item: ContextMenuItem) => void;
show?: (player: Player, item: ContextMenuItem) => void;
click?: (player: Player, item: ContextMenuItem) => void;
}
interface Plugin {
apply: (player: Player) => void;
dispose?: () => void;
}