Skip to main content

Event

player objects trigger events that can be listened, using on,once method,emit with custom or defined events.Event name is a upper camel case string.

You can access these constant event string using EVENT static attributes or player instance EVENT.

import Player, { EVENT } from 'nplayer'
const player = new Player()
console.log(EVENT.LOADING_SHOW)
console.log(Player.EVENT.LOADING_SHOW)
console.log(player.EVENT.LOADING_SHOW)
console.log('LoadingShow')
// same strings
const noop = () => {}
player.on(EVENT.LOADING_SHOW, noop)
player.once(EVENT.LOADING_SHOW, noop)
player.off(EVENT.LOADING_SHOW, noop)
player.emit(EVENT.LOADING_SHOW)

Event List#

Event NameDescription
EnterFullscreenEnter fullscreen
ExitFullscreenExit fullscreen
WebEnterFullscreenEnter web fullscreen
WebExitFullscreenExit web fullscreen
LoadingShowVideo loading display
LoadingHideVideo loading hidden
ControlShowControl bar display
ControlHideControl bar hidden
ControlItemUpdateTrigger when updating control bar-item location, call player.updateControlItems()
EnterPipEnter Picture in Picture
ExitPipExit Picture in Picture
UpdateSizeUpdate player size, such as window size triggers. When externally changes player size, the event can be triggered manually to prevent player component misplaced
UpdateOptionsUpdate configuration
AfterInitTrigger when player initialization finishes
MountedPlayer mounted
BeforeDisposeTrigger before the player is destroyed when calling dispose methods
OpenEdgeAutomatically open the edge browser in IE and trigger when accessing the web page
Play同 video play 事件
Pause同 video pause 事件
Ended同 video ended 事件
Waiting同 video waiting 事件
Stalled同 video stalled 事件
Canplay同 video canplay 事件
LoadedMetadata同 video loadedmetadata 事件
Error同 video error 事件
Seeked同 video seeked 事件
TimeUpdate同 video timeupdate 事件
VolumeChange同 video volumechange 事件
RateChange同 video ratechange 事件
DurationChange同 video durationchange 事件
Progress同 video progress 事件
BpChangeBreakpoint set in the parameterbpControls when player size changes to a particular breakpoint