# Guide

Get a NeoPlayer instance on the page, then add the controls and media features you need.

# Installation

npm install neoplayer

# Quick start

Add a container to your page. Import NeoPlayer and its stylesheet in your application code.

<div id="player"></div>
import NeoPlayer from 'neoplayer';
import 'neoplayer/dist/NeoPlayer.css';

const container = document.getElementById('player');

if (container) {
    const player = new NeoPlayer({
        container,
        video: {
            url: '/movie.mp4',
            type: 'normal',
        },
    });
}

Give the container a width. NeoPlayer fills that width and keeps the video's aspect ratio.

#player {
    max-width: 960px;
}

# Video sources

Set video.url to the media URL. NeoPlayer detects common streaming formats when type is auto.

Type Format Extra library
normal MP4, WebM and browser-supported video None
hls HLS playlists hls.js
dash MPEG-DASH dash.js
flv FLV flv.js
webtorrent WebTorrent WebTorrent

Load the relevant library before creating the player. You can also supply a custom playback function through video.customType.

const player = new NeoPlayer({
    container: document.getElementById('player')!,
    video: {
        url: '/stream.m3u8',
        type: 'hls',
    },
});

# Quality selection

Provide a list of sources and the initial quality index.

const player = new NeoPlayer({
    container: document.getElementById('player')!,
    video: {
        quality: [
            { name: '1080p', url: '/movie-1080.mp4', type: 'normal' },
            { name: '720p', url: '/movie-720.mp4', type: 'normal' },
        ],
        defaultQuality: 0,
    },
});

# Player options

Option Purpose
container Required HTML element for the player
video Required media source or quality list
autoplay Start playback when allowed by the browser
theme Accent color, such as '#dafa75'
loop Repeat the current video
volume Initial volume from 0 to 1
hotkey Enable player keyboard shortcuts
screenshot Show the camera button
lang Interface language
subtitle External subtitle track
danmaku Timed comment connection
contextmenu Additional menu items
highlight Mark selected moments on the progress bar

# Keyboard shortcuts

Keyboard shortcuts work when the player has focus.

Key Action
Space Play or pause
← / → Seek back or forward 5 seconds
↑ / ↓ Change volume
A / D Seek back or forward 5 seconds
+ / - Change playback speed
Backspace Reset playback speed
P Download the current frame as a PNG
F Browser fullscreen
W / E Web fullscreen
M Mute or unmute
0–9 Jump to 0%–90% of the video

# Screenshots

Set screenshot: true to show the camera control. The camera button and P shortcut capture the current video frame at its original resolution.

const player = new NeoPlayer({
    container: document.getElementById('player')!,
    screenshot: true,
    video: { url: '/movie.mp4', type: 'normal' },
});

The video source must allow canvas access. A local file or a cross-origin source with the appropriate CORS headers works.

# Danmaku

Set danmaku when you have a compatible comment API. The id identifies the video in that service.

const player = new NeoPlayer({
    container: document.getElementById('player')!,
    video: { url: '/movie.mp4', type: 'normal' },
    danmaku: {
        id: 'movie-1',
        api: 'https://your-comment-service.example/api/',
        user: 'viewer',
    },
});

# JavaScript API

Use the player instance to control playback or react to events.

player.play();
player.pause();
player.seek(30);
player.volume(0.5);
player.speed(1.25);
player.switchQuality(1);
player.switchVideo({ url: '/another-movie.mp4', type: 'normal' });

player.on('play', () => console.log('Playback started'));
player.on('screenshot', () => console.log('Frame captured'));

player.destroy();

switchQuality applies when video.quality is configured. Call destroy() when removing the player from the page.

# Live demo