Menu

Class Player

Flipnote Player API (exported as flipnote.Player) - provides a MediaElement-like interface for loading Flipnotes and playing them. This is intended for cases where you want to implement your own player UI, if you just want a pre-built player with some nice UI controls, check out the Web Components page instead!

Create a new player

You'll need an element in your page's HTML to act as a wrapper for the player:

 <div id="player-wrapper"></div>

Then you can create a new Player instance by passing a CSS selector that matches the wrapper element, plus the desired width and height.

 const player = new flipnote.Player('#player-wrapper', 320, 240);

Load a Flipnote

Load a Flipnote from a valid FlipnoteSource:

player.load('./path/to/flipnote.ppm');

Listen to events

Use the on method to register event listeners:

 player.on('play', function() {
   // do something when the Flipnote starts playing...
 });

Hierarchy

  • Player

Index

Constructors

HTMLVideoElement compatibility Events

audio Events

frame Events

lifecycle Events

playback Events

Properties

HTMLVideoElement compatibility Accessors

Other Accessors

Audio Control Methods

Display Control Methods

Event API Methods

Frame Control Methods

HTMLVideoElement compatibility Methods

Lifecycle Methods

Other Methods

Playback Control Methods

Constructors

constructor

  • Create a new Player instance

    Parameters

    • parent: string | Element

      Element to mount the rendering canvas to

    • width: number

      Canvas width (pixels)

    • height: number

      Canvas height (pixels)

      The ratio between width and height should be 3:4 for best results

    • Default value parserSettings: FlipnoteParserSettings = {}

    Returns Player

HTMLVideoElement compatibility Events

canplay

canplay: () => void

Fired when the Flipnote has loaded enough to begin animation play

Type declaration

    • (): void
    • Returns void

canplaythrough

canplaythrough: () => void

Fired when the Flipnote has loaded enough to play successfully

Type declaration

    • (): void
    • Returns void

durationchange

durationchange: () => void

Fired when the animation duration has changed

Type declaration

    • (): void
    • Returns void

emptied

emptied: () => void

Fired when the media has become empty; implementation of the HTMLMediaElement https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/emptied_event event.

Type declaration

    • (): void
    • Returns void

loadeddata

loadeddata: () => void

Fired when the Flipnote data has been loaded; implementation of the HTMLMediaElement https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/loadeddata_event event.

Type declaration

    • (): void
    • Returns void

loadedmetadata

loadedmetadata: () => void

Fired when the Flipnote metadata has been loaded; implementation of the HTMLMediaElement https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/loadedmetadata_event event.

Type declaration

    • (): void
    • Returns void

audio Events

volumechange

volumechange: (volume: number) => void

Fired when the player audio volume or muted state has changed

Type declaration

    • (volume: number): void
    • Parameters

      • volume: number

      Returns void

frame Events

framefirst

framefirst: () => void

Fired when firstFrame has been called

Type declaration

    • (): void
    • Returns void

framelast

framelast: () => void

Fired when lastFrame has been called

Type declaration

    • (): void
    • Returns void

framenext

framenext: () => void

Fired when nextFrame has been called

Type declaration

    • (): void
    • Returns void

frameprev

frameprev: () => void

Fired when prevFrame has been called

Type declaration

    • (): void
    • Returns void

frameupdate

frameupdate: (frameIndex: number) => void

Fired when the current frame index has changed

Type declaration

    • (frameIndex: number): void
    • Parameters

      • frameIndex: number

      Returns void

lifecycle Events

close

close: () => void

Fired after the Flipnote has been closed with close

Type declaration

    • (): void
    • Returns void

destroy

destroy: () => void

Fired just before the player has been destroyed, after calling destroy

Type declaration

    • (): void
    • Returns void

error

error: (err?: Error) => void

Fired after a loading, parsing or playback error occurs

Type declaration

    • (err?: Error): void
    • Parameters

      • Optional err: Error

      Returns void

load

load: () => void

Fired when a Flipnote has finished loading

Type declaration

    • (): void
    • Returns void

loadstart

loadstart: () => void

Fired when a Flipnote has begun loading

Type declaration

    • (): void
    • Returns void

ready

ready: () => void

Fired when a Flipnote is ready for playback

Type declaration

    • (): void
    • Returns void

playback Events

ended

ended: () => void

Fired when playback has ended

Type declaration

    • (): void
    • Returns void

loop

loop: () => void

Fired when playback has looped after reaching the end

Type declaration

    • (): void
    • Returns void

pause

pause: () => void

Fired when animation playback is paused

Type declaration

    • (): void
    • Returns void

play

play: () => void

Fired when animation playback begins or is resumed

Type declaration

    • (): void
    • Returns void

progress

progress: (progress: number) => void

Fired when playback progress has changed

Type declaration

    • (progress: number): void
    • Parameters

      • progress: number

      Returns void

seeked

seeked: () => void

Fired when a seek operation completes

Type declaration

    • (): void
    • Returns void

seeking

seeking: () => void

Fired when a seek operation begins

Type declaration

    • (): void
    • Returns void

timeupdate

timeupdate: (time: number) => void

Fired when the playback time has changed

Type declaration

    • (time: number): void
    • Parameters

      • time: number

      Returns void

Properties

audio

Audio player

autoplay

autoplay: boolean = false

Automatically begin playback after a Flipnote is loaded

canvasEl

canvasEl: HTMLCanvasElement

Canvas HTML element

duration

duration: number = 0

Animation duration, in seconds

el

el: Element

Root element

layerVisibility

layerVisibility: PlayerLayerVisibility

Animation layer visibility

meta

Metadata for the currently loaded Flipnote

note

note: Flipnote

Currently loaded Flipnote

noteFormat

noteFormat: FlipnoteFormat

Format of the currently loaded Flipnote

parserSettings

parserSettings: FlipnoteParserSettings

Flipnote parser settings

renderer

renderer: UniversalCanvas

Frame renderer

supportedEvents

supportedEvents: PlayerEvent[] = supportedEvents

Array of events supported by this player

HTMLVideoElement compatibility Accessors

buffered

  • get buffered(): TimeRanges

currentSrc

seekable

  • get seekable(): TimeRanges

videoHeight

  • get videoHeight(): number

videoWidth

  • get videoWidth(): number

Other Accessors

currentFrame

  • get currentFrame(): number
  • set currentFrame(frameIndex: number): void

currentTime

  • get currentTime(): number
  • set currentTime(value: number): void

frameCount

  • get frameCount(): number

frameSpeed

  • get frameSpeed(): number

framerate

  • get framerate(): number

loop

  • get loop(): boolean
  • set loop(value: boolean): void
  • Indicates whether playback should loop once the end is reached

    Returns boolean

  • Indicates whether playback should loop once the end is reached

    Parameters

    • value: boolean

    Returns void

muted

  • get muted(): boolean
  • set muted(value: boolean): void

paused

  • get paused(): boolean
  • set paused(isPaused: boolean): void

progress

  • get progress(): number
  • set progress(value: number): void
  • Current animation playback progress, as a percentage out of 100

    Returns number

  • Current animation playback progress, as a percentage out of 100

    Parameters

    • value: number

    Returns void

src

volume

  • get volume(): number
  • set volume(value: number): void

Audio Control Methods

getMuted

  • getMuted(): boolean

getVolume

  • getVolume(): number

mute

  • mute(): void

setAudioEq

  • setAudioEq(state: boolean): void
  • Turn audio Sudomemo equalizer filter on or off

    Parameters

    • state: boolean

    Returns void

setMuted

  • setMuted(isMute: boolean): void

setVolume

  • setVolume(volume: number): void

toggleAudioEq

  • toggleAudioEq(): void

toggleMuted

  • toggleMuted(): void

unmute

  • unmute(): void

Display Control Methods

drawFrame

  • drawFrame(frameIndex: number): void
  • Draws the specified animation frame to the canvas. Note that this doesn't update the playback time or anything, it simply decodes a given frame and displays it.

    Parameters

    • frameIndex: number

    Returns void

forceUpdate

  • forceUpdate(): void

getLayerVisibility

  • getLayerVisibility(layer: number): boolean
  • Returns the visibility state for a given layer

    Parameters

    • layer: number

      layer index, starting at 1

    Returns boolean

resize

  • resize(width: number, height: number): void
  • Resize the playback canvas to a new size

    Parameters

    • width: number

      new canvas width (pixels)

    • height: number

      new canvas height (pixels)

      The ratio between width and height should be 3:4 for best results

    Returns void

setLayerVisibility

  • setLayerVisibility(layer: number, value: boolean): void
  • Sets whether an animation layer should be visible throughout the entire animation

    Parameters

    • layer: number

      layer index, starting at 1

    • value: boolean

      true for visible, false for invisible

    Returns void

toggleLayerVisibility

  • toggleLayerVisibility(layerIndex: number): void
  • Toggles whether an animation layer should be visible throughout the entire animation

    Parameters

    • layerIndex: number

    Returns void

Event API Methods

clearEvents

  • clearEvents(): void

emit

off

on

Frame Control Methods

firstFrame

  • firstFrame(): void

lastFrame

  • lastFrame(): void

nextFrame

  • nextFrame(): void
  • Jump to the next animation frame If the animation loops, and is currently on its last frame, it will wrap to the first frame

    Returns void

prevFrame

  • prevFrame(): void
  • Jump to the next animation frame If the animation loops, and is currently on its first frame, it will wrap to the last frame

    Returns void

setCurrentFrame

  • setCurrentFrame(newFrameValue: number): void

thumbnailFrame

  • thumbnailFrame(): void

HTMLVideoElement compatibility Methods

canPlayType

  • canPlayType(mediaType: string): "" | "probably" | "maybe"

captureStream

  • captureStream(): void

fastSeek

  • fastSeek(time: number): void

getVideoPlaybackQuality

  • getVideoPlaybackQuality(): VideoPlaybackQuality

requestPictureInPicture

  • requestPictureInPicture(): void

seekToNextFrame

  • seekToNextFrame(): void

Lifecycle Methods

closeNote

  • closeNote(): void

destroy

  • destroy(): Promise<void>

load

openNote

Other Methods

playAudio

  • playAudio(): void

reload

  • reload(): Promise<void>

stopAudio

  • stopAudio(): void

supports

  • supports(name: string): boolean
  • Returns true if the player supports a given event or method name

    Parameters

    • name: string

    Returns boolean

updateSettings

Playback Control Methods

endSeek

  • endSeek(): void

getCurrentTime

  • getCurrentTime(): number

getDuration

  • getDuration(): number

getFrameCounter

  • getFrameCounter(): string

getLoop

  • getLoop(): boolean

getPaused

  • getPaused(): boolean

getProgress

  • getProgress(): number

getTimeCounter

  • getTimeCounter(): string

pause

  • pause(): void

play

  • play(): Promise<void>

seek

  • seek(position: number): void
  • Seek the playback progress to a different position

    Parameters

    • position: number

      animation playback position, range 0 to 1

    Returns void

setCurrentTime

  • setCurrentTime(value: number): void

setLoop

  • setLoop(loop: boolean): void

setProgress

  • setProgress(value: number): void
  • Set the current playback progress as a percentage (0 to 100)

    Parameters

    • value: number

    Returns void

startSeek

  • startSeek(): void

toggleLoop

  • toggleLoop(): void

togglePlay

  • togglePlay(): void